from django.contrib import admin

from apps.standards.models import (
    StandardSource,
    StandardCategory,
    Standard,
    StandardCompliance,
    StandardAttachment
)


@admin.register(StandardSource)
class StandardSourceAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'is_active', 'created_at']
    list_filter = ['is_active', 'created_at']
    search_fields = ['name', 'name_ar', 'code', 'description']
    ordering = ['name']


@admin.register(StandardCategory)
class StandardCategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'order', 'is_active', 'created_at']
    list_filter = ['is_active', 'created_at']
    search_fields = ['name', 'name_ar', 'description']
    ordering = ['order', 'name']


@admin.register(Standard)
class StandardAdmin(admin.ModelAdmin):
    list_display = ['code', 'title', 'source', 'category', 'department', 'is_active', 'effective_date']
    list_filter = ['source', 'category', 'department', 'is_active', 'effective_date']
    search_fields = ['code', 'title', 'title_ar', 'description']
    ordering = ['source', 'category', 'code']
    date_hierarchy = 'effective_date'


@admin.register(StandardCompliance)
class StandardComplianceAdmin(admin.ModelAdmin):
    list_display = ['department', 'standard', 'status', 'last_assessed_date', 'assessor', 'created_at']
    list_filter = ['status', 'last_assessed_date', 'created_at']
    search_fields = ['department__name', 'standard__code', 'standard__title', 'notes', 'evidence_summary']
    ordering = ['-created_at']
    raw_id_fields = ['department', 'standard', 'assessor']


@admin.register(StandardAttachment)
class StandardAttachmentAdmin(admin.ModelAdmin):
    list_display = ['filename', 'compliance', 'uploaded_by', 'created_at']
    list_filter = ['created_at']
    search_fields = ['filename', 'description']
    ordering = ['-created_at']
    raw_id_fields = ['compliance', 'uploaded_by']
