from django.contrib import admin
from .models import ChatSession, ChatMessage


class ChatMessageInline(admin.TabularInline):
    model = ChatMessage
    extra = 1
    fields = ("role", "content", "language", "timestamp")
    readonly_fields = ("timestamp",)
    show_change_link = True


@admin.register(ChatSession)
class ChatSessionAdmin(admin.ModelAdmin):
    list_display = ("id", "title", "user", "created_at", "updated_at")
    list_filter = ("user", "created_at")
    search_fields = ("title", "user__username", "messages__content")
    inlines = [ChatMessageInline]
    readonly_fields = ("created_at", "updated_at")


@admin.register(ChatMessage)
class ChatMessageAdmin(admin.ModelAdmin):
    list_display = ("session", "role", "content", "timestamp", "language")
    list_filter = ("session", "role", "language")
    search_fields = ("content",)
    readonly_fields = ("timestamp",)
