from django.contrib import admin
from django.contrib.admin import display
from mptt.admin import MPTTModelAdmin

from .models import Category, Checklist, GlobalSettings, PaymentMethod, Promocode, Image, Gift


@admin.register(Category)
class CategoryAdmin(MPTTModelAdmin):
    list_display = ('name', 'delivery_price_CN_RU', 'commission')
    ordering = ('id',)


@admin.register(Image)
class ImageAdmin(admin.ModelAdmin):
    pass


@admin.register(Checklist)
class ChecklistAdmin(admin.ModelAdmin):
    list_display = ('id', 'brand', 'model', 'price_rub', 'commission_rub', 'full_price', 'date', 'status_display')
    ordering = ('-status_updated_at', '-created_at')

    @display(description='Статус')
    def status_display(self, obj: Checklist):
        return obj.get_status_display()

    def date(self, obj: Checklist):
        return obj.status_updated_at or obj.created_at

    def get_queryset(self, request):
        return Checklist.objects.with_base_related()


@admin.register(GlobalSettings)
class GlobalSettingsAdmin(admin.ModelAdmin):
    pass


@admin.register(PaymentMethod)
class PaymentMethodAdmin(admin.ModelAdmin):
    list_display = ('name', 'slug')


@admin.register(Promocode)
class PromoCodeAdmin(admin.ModelAdmin):
    list_display = ('name', 'discount', 'free_delivery', 'no_comission')


@admin.register(Gift)
class GiftAdmin(admin.ModelAdmin):
    list_display = ('name', 'min_price')




