from django.contrib import admin
from django.contrib.admin import display

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


@admin.register(User)
class UserAdmin(admin.ModelAdmin):
    list_display = ('email', 'job_title', 'full_name',)


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ('slug', 'name')
    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', '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().annotate_price_rub().annotate_commission_rub()


@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')




