from django.contrib import admin
from .models import Category, Question, GameSession, Player, RoundConfig, RoundQuestion, LieAnswer, Guess, ScoreEvent


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ("name", "slug", "is_active")
    list_filter = ("is_active",)
    search_fields = ("name", "slug")


@admin.register(Question)
class QuestionAdmin(admin.ModelAdmin):
    list_display = ("id", "category", "is_active")
    list_filter = ("category", "is_active")
    search_fields = ("prompt", "correct_answer")


class PlayerInline(admin.TabularInline):
    model = Player
    extra = 0


@admin.register(GameSession)
class GameSessionAdmin(admin.ModelAdmin):
    list_display = ("code", "host", "status", "current_round", "created_at")
    list_filter = ("status",)
    inlines = [PlayerInline]
    search_fields = ("code", "host__username")


@admin.register(RoundConfig)
class RoundConfigAdmin(admin.ModelAdmin):
    list_display = ("session", "number", "category", "questions_count", "points_correct", "points_bluff")
    list_filter = ("category",)


@admin.register(RoundQuestion)
class RoundQuestionAdmin(admin.ModelAdmin):
    list_display = ("session", "round_number", "question")


@admin.register(LieAnswer)
class LieAnswerAdmin(admin.ModelAdmin):
    list_display = ("round_question", "player", "text", "created_at")


@admin.register(Guess)
class GuessAdmin(admin.ModelAdmin):
    list_display = ("round_question", "player", "selected_text", "is_correct", "fooled_player")
    list_filter = ("is_correct",)


@admin.register(ScoreEvent)
class ScoreEventAdmin(admin.ModelAdmin):
    list_display = ("session", "player", "delta", "reason", "created_at")
    list_filter = ("reason",)
