# admin.py
from django.contrib import admin
from .models import Product, AttributeScore, CategoryAttributeRule

# -------------------------
# Product Admin
# -------------------------
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ('sku', 'title', 'category', 'created_at', 'updated_at')
    search_fields = ('sku', 'title', 'category')
    list_filter = ('category', 'created_at', 'updated_at')
    readonly_fields = ('created_at', 'updated_at')
    ordering = ('-created_at',)

# -------------------------
# AttributeScore Admin
# -------------------------
@admin.register(AttributeScore)
class AttributeScoreAdmin(admin.ModelAdmin):
    list_display = ('product', 'score', 'max_score', 'processing_time', 'created_at')
    search_fields = ('product__sku', 'product__title')
    list_filter = ('created_at',)
    readonly_fields = ('created_at',)
    ordering = ('-created_at',)
    autocomplete_fields = ('product',)  # makes it easier to select products in large DB

# -------------------------
# CategoryAttributeRule Admin
# -------------------------
@admin.register(CategoryAttributeRule)
class CategoryAttributeRuleAdmin(admin.ModelAdmin):
    list_display = ('category', 'attribute_name', 'is_mandatory', 'data_type')
    search_fields = ('category', 'attribute_name')
    list_filter = ('category', 'is_mandatory', 'data_type')
    ordering = ('category', 'attribute_name')
