"""
Feedback admin configuration
"""
from django.contrib import admin

from .models import Feedback, FeedbackAttachment, FeedbackResponse


@admin.register(Feedback)
class FeedbackAdmin(admin.ModelAdmin):
    """Admin interface for Feedback model"""
    list_display = [
        'id', 'feedback_type', 'title', 'get_contact_name', 'hospital',
        'status', 'sentiment', 'rating', 'is_featured', 'created_at'
    ]
    list_filter = [
        'feedback_type', 'status', 'sentiment', 'category',
        'priority', 'is_featured', 'is_deleted', 'created_at'
    ]
    search_fields = [
        'title', 'message', 'patient__first_name', 'patient__last_name',
        'patient__mrn', 'contact_name', 'contact_email'
    ]
    readonly_fields = [
        'id', 'created_at', 'updated_at', 'assigned_at', 'reviewed_at',
        'acknowledged_at', 'closed_at', 'deleted_at'
    ]
    fieldsets = (
        ('Basic Information', {
            'fields': (
                'id', 'feedback_type', 'title', 'message', 'category',
                'subcategory', 'rating', 'priority'
            )
        }),
        ('Patient/Contact', {
            'fields': (
                'patient', 'is_anonymous', 'contact_name', 'contact_email',
                'contact_phone'
            )
        }),
        ('Organization', {
            'fields': ('hospital', 'department', 'physician', 'encounter_id')
        }),
        ('Status & Workflow', {
            'fields': (
                'status', 'assigned_to', 'assigned_at', 'reviewed_by',
                'reviewed_at', 'acknowledged_by', 'acknowledged_at',
                'closed_by', 'closed_at'
            )
        }),
        ('Sentiment Analysis', {
            'fields': ('sentiment', 'sentiment_score')
        }),
        ('Flags', {
            'fields': (
                'is_featured', 'is_public', 'requires_follow_up',
                'is_deleted', 'deleted_at', 'deleted_by'
            )
        }),
        ('Metadata', {
            'fields': ('source', 'metadata', 'created_at', 'updated_at'),
            'classes': ('collapse',)
        }),
    )
    date_hierarchy = 'created_at'
    ordering = ['-created_at']


@admin.register(FeedbackAttachment)
class FeedbackAttachmentAdmin(admin.ModelAdmin):
    """Admin interface for FeedbackAttachment model"""
    list_display = [
        'id', 'feedback', 'filename', 'file_type', 'file_size',
        'uploaded_by', 'created_at'
    ]
    list_filter = ['file_type', 'created_at']
    search_fields = ['filename', 'feedback__title']
    readonly_fields = ['id', 'created_at', 'updated_at']
    date_hierarchy = 'created_at'
    ordering = ['-created_at']


@admin.register(FeedbackResponse)
class FeedbackResponseAdmin(admin.ModelAdmin):
    """Admin interface for FeedbackResponse model"""
    list_display = [
        'id', 'feedback', 'response_type', 'created_by',
        'is_internal', 'created_at'
    ]
    list_filter = ['response_type', 'is_internal', 'created_at']
    search_fields = ['message', 'feedback__title']
    readonly_fields = ['id', 'created_at', 'updated_at']
    fieldsets = (
        ('Response Information', {
            'fields': (
                'id', 'feedback', 'response_type', 'message',
                'created_by', 'is_internal'
            )
        }),
        ('Status Change', {
            'fields': ('old_status', 'new_status')
        }),
        ('Metadata', {
            'fields': ('metadata', 'created_at', 'updated_at'),
            'classes': ('collapse',)
        }),
    )
    date_hierarchy = 'created_at'
    ordering = ['-created_at']
