from django.contrib import admin

from .models import PilotCall, WebhookEvent


@admin.register(PilotCall)
class PilotCallAdmin(admin.ModelAdmin):
    list_display = ('client_name', 'phone', 'call_source', 'ytel_audio_status', 'logics_api_status', 'created_at')
    list_filter = ('call_source', 'ytel_audio_status', 'logics_api_status', 'levy', 'garnishment')
    search_fields = ('client_name', 'phone', 'email', 'transcript', 'agent_notes')
    readonly_fields = ('created_at', 'updated_at')



@admin.register(WebhookEvent)
class WebhookEventAdmin(admin.ModelAdmin):
    list_display = ('provider', 'display_event_type', 'external_id', 'delivery_id', 'source_ip', 'processed', 'received_at')
    list_filter = ('provider', 'event_type', 'processed', 'received_at')
    search_fields = ('provider', 'event_type', 'external_id', 'delivery_id', 'raw_body', 'notes')
    readonly_fields = ('provider', 'event_type', 'external_id', 'delivery_id', 'source_ip', 'content_type', 'headers', 'query_params', 'payload', 'raw_body', 'received_at')
    list_editable = ('processed',)
    fieldsets = (
        ('Routing summary', {'fields': ('provider', 'event_type', 'external_id', 'delivery_id', 'source_ip', 'content_type', 'received_at')}),
        ('Payload', {'fields': ('query_params', 'headers', 'payload', 'raw_body')}),
        ('Review', {'fields': ('processed', 'notes')}),
    )
