from django.contrib import admin
from .models import GenerationRecord, QuotaConfig


@admin.register(GenerationRecord)
class GenerationRecordAdmin(admin.ModelAdmin):
    list_display = ('task_id', 'user', 'mode', 'model', 'duration', 'seconds_consumed', 'status', 'created_at')
    list_filter = ('status', 'mode', 'model', 'created_at')
    search_fields = ('user__username', 'prompt', 'task_id')
    readonly_fields = ('task_id', 'created_at')
    date_hierarchy = 'created_at'


@admin.register(QuotaConfig)
class QuotaConfigAdmin(admin.ModelAdmin):
    list_display = ('default_daily_seconds_limit', 'default_monthly_seconds_limit', 'announcement_enabled', 'updated_at')

    def has_add_permission(self, request):
        # Singleton: only allow one record
        return not QuotaConfig.objects.exists()

    def has_delete_permission(self, request, obj=None):
        return False
