from django.contrib import admin
from . import models


admin.site.register(models.Dealer)
admin.site.register(models.Vendor)
admin.site.register(models.Customer)
admin.site.register(models.SaleQuotation)
admin.site.register(models.SaleQuotationCar)
admin.site.register(models.Car)
admin.site.register(models.CarFinance)
admin.site.register(models.CarColors)
admin.site.register(models.CarRegistration)
admin.site.register(models.CustomCard)
admin.site.register(models.CarSpecificationValue)
admin.site.register(models.ExteriorColors)
admin.site.register(models.InteriorColors)

@admin.register(models.CarMake)
class CarMakeAdmin(admin.ModelAdmin):
    list_display = ('name', 'arabic_name', 'is_sa_import')
    search_fields = ('name', 'arabic_name')
    list_filter = ('is_sa_import', 'name',)

    class Meta:
        verbose_name = "Car Make"
        ordering = ('name',)


@admin.register(models.CarModel)
class CarModelAdmin(admin.ModelAdmin):
    list_display = ('name', 'arabic_name', 'id_car_make', 'get_is_sa_import')
    search_fields = ('name', 'arabic_name')
    list_filter = ('id_car_make__is_sa_import', 'id_car_make')
    sortable_by = ['name', 'arabic_name', 'id_car_make']

    def get_is_sa_import(self, obj):
        return obj.id_car_make.is_sa_import
    get_is_sa_import.boolean = True
    get_is_sa_import.short_description = 'Is SA Import'

    class Meta:
        verbose_name = "Car Model"
        ordering = ('name',)


@admin.register(models.CarSerie)
class CarSeriesAdmin(admin.ModelAdmin):
    list_display = ('name', 'arabic_name', 'id_car_model', )
    search_fields = ('name', 'id_car_model__name')
    list_filter = ('id_car_model__id_car_make__is_sa_import',
                   'id_car_model__id_car_make__name',)

    class Meta:
        verbose_name = "Car Series"


@admin.register(models.CarTrim)
class CarTrimAdmin(admin.ModelAdmin):
    list_display = ('name',
                    'id_car_serie__name',
                    'id_car_serie__id_car_model__name',
                    'id_car_serie__id_car_model__id_car_make__name')
    search_fields = ('name', 'arabic_name', 'id_car_serie__id_car_model__name')
    list_filter = ('id_car_serie__id_car_model__id_car_make__is_sa_import',
                   'id_car_serie__id_car_model__id_car_make__name')

    class Meta:
        verbose_name = "Car Trim"


@admin.register(models.CarSpecification)
class CarSpecificationAdmin(admin.ModelAdmin):
    list_display = ('name', 'arabic_name', 'id_parent')
    search_fields = ('name', 'id_parent')
    list_filter = ('id_parent',)

    class Meta:
        verbose_name = "Car Specification"

