# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later

from django.contrib import admin
from polymorphic.admin import PolymorphicChildModelAdmin, PolymorphicParentModelAdmin
from note_kfet.admin import admin_site

from .models import Allergen, Food, BasicFood, TransformedFood, QRCode


@admin.register(Allergen, site=admin_site)
class AllergenAdmin(admin.ModelAdmin):
    """
    Admin customisation for Allergen
    """
    ordering = ['name']


@admin.register(Food, site=admin_site)
class FoodAdmin(PolymorphicParentModelAdmin):
    """
    Admin customisation for Food
    """
    child_models = (Food, BasicFood, TransformedFood)
    list_display = ('name', 'expiry_date', 'owner', 'is_ready')
    list_filter = ('is_ready', 'end_of_life')
    search_fields = ['name']
    ordering = ['expiry_date', 'name']


@admin.register(BasicFood, site=admin_site)
class BasicFood(PolymorphicChildModelAdmin):
    """
    Admin customisation for BasicFood
    """
    list_display = ('name', 'expiry_date', 'date_type', 'owner', 'is_ready')
    list_filter = ('is_ready', 'date_type', 'end_of_life')
    search_fields = ['name']
    ordering = ['expiry_date', 'name']


@admin.register(TransformedFood, site=admin_site)
class TransformedFood(PolymorphicChildModelAdmin):
    """
    Admin customisation for TransformedFood
    """
    list_display = ('name', 'expiry_date', 'shelf_life', 'owner', 'is_ready')
    list_filter = ('is_ready', 'end_of_life', 'shelf_life')
    search_fields = ['name']
    ordering = ['expiry_date', 'name']


@admin.register(QRCode, site=admin_site)
class QRCodeAdmin(admin.ModelAdmin):
    """
    Admin customisation for QRCode
    """
    list_diplay = ('qr_code_number', 'food_container')
    search_fields = ['food_container__name']
