from django.contrib import admin

from .models import Ticket, TicketReply


class TicketReplyInline(admin.TabularInline):
    model = TicketReply
    extra = 0
    fields = ("author_name", "author_email", "body", "is_staff_reply", "created_at")
    readonly_fields = ("created_at",)


@admin.register(Ticket)
class TicketAdmin(admin.ModelAdmin):
    list_display = ("ticket_number", "subject", "requester_name", "status", "priority", "category", "assigned_to", "updated_at")
    list_filter = ("status", "priority", "category", "created_at")
    search_fields = ("subject", "description", "requester_name", "requester_email")
    readonly_fields = ("public_id", "created_at", "updated_at")
    inlines = [TicketReplyInline]


@admin.register(TicketReply)
class TicketReplyAdmin(admin.ModelAdmin):
    list_display = ("ticket", "author_name", "is_staff_reply", "created_at")
    list_filter = ("is_staff_reply", "created_at")
    search_fields = ("author_name", "author_email", "body", "ticket__subject")
