from django.contrib import admin
from .models import (
    Category, Project, Coupon, Banner, Student, StudentCoupon,
    Activity, Showcase, Exam, StudentHonor, StudentLevel,
    CourseRegistration, ActivityRegistration, ExamRegistration
)

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ('name', 'color')
    search_fields = ('name',)

@admin.register(Project)
class ProjectAdmin(admin.ModelAdmin):
    list_display = ('title', 'category', 'students', 'rating', 'created_at')
    list_filter = ('category', 'created_at')
    search_fields = ('title',)

@admin.register(Coupon)
class CouponAdmin(admin.ModelAdmin):
    list_display = ('title', 'amount', 'unit', 'expiry', 'status', 'issue_type')
    list_filter = ('status', 'expiry', 'issue_type')
    search_fields = ('title',)
    filter_horizontal = ('applicable_projects',)

@admin.register(Banner)
class BannerAdmin(admin.ModelAdmin):
    list_display = ('id', 'image', 'link', 'sort_order', 'is_active')
    list_editable = ('sort_order', 'is_active')

@admin.register(Student)
class StudentAdmin(admin.ModelAdmin):
    list_display = ('name', 'phone', 'age', 'learning_count', 'created_at')
    search_fields = ('name', 'phone')
    inlines = []

class StudentCouponInline(admin.TabularInline):
    model = StudentCoupon
    extra = 1

StudentAdmin.inlines = [StudentCouponInline]

@admin.register(StudentCoupon)
class StudentCouponAdmin(admin.ModelAdmin):
    list_display = ('student', 'coupon', 'status', 'assigned_at')
    list_filter = ('status',)
    search_fields = ('student__name', 'coupon__title')

@admin.register(Activity)
class ActivityAdmin(admin.ModelAdmin):
    list_display = ('title', 'start_time', 'status', 'current_participants', 'max_participants')
    list_filter = ('status', 'start_time')
    search_fields = ('title', 'location')

@admin.register(Showcase)
class ShowcaseAdmin(admin.ModelAdmin):
    list_display = ('title', 'media_type', 'created_at')
    list_filter = ('media_type', 'created_at')
    search_fields = ('title',)

@admin.register(Exam)
class ExamAdmin(admin.ModelAdmin):
    list_display = ('title', 'exam_date', 'level', 'fee', 'deadline')
    list_filter = ('level', 'exam_date')
    search_fields = ('title',)

@admin.register(StudentHonor)
class StudentHonorAdmin(admin.ModelAdmin):
    list_display = ('student', 'title', 'date_awarded')
    search_fields = ('student__name', 'title')

@admin.register(StudentLevel)
class StudentLevelAdmin(admin.ModelAdmin):
    list_display = ('student', 'level', 'date_passed', 'exam')
    list_filter = ('level',)
    search_fields = ('student__name', 'level')

@admin.register(CourseRegistration)
class CourseRegistrationAdmin(admin.ModelAdmin):
    list_display = ('student', 'project', 'status', 'created_at')
    list_filter = ('status', 'created_at')
    search_fields = ('student__name', 'project__title')

@admin.register(ActivityRegistration)
class ActivityRegistrationAdmin(admin.ModelAdmin):
    list_display = ('student', 'activity', 'status', 'created_at')
    list_filter = ('status', 'created_at')
    search_fields = ('student__name', 'activity__title')

@admin.register(ExamRegistration)
class ExamRegistrationAdmin(admin.ModelAdmin):
    list_display = ('student', 'exam', 'status', 'created_at')
    list_filter = ('status', 'created_at')
    search_fields = ('student__name', 'exam__title')
