from django.contrib import admin
from .models import AccessLog, Hit, Site


@admin.register(AccessLog)
class AccessLogAdmin(admin.ModelAdmin):
    list_display = ("created_at", "resource_type", "resource_id", "status_code", "country", "device", "browser", "referer_host")
    list_filter = ("resource_type", "device", "browser", "country", "country_code")
    search_fields = ("resource_id", "resource_slug", "path", "referer_host", "utm_source", "utm_campaign")
    readonly_fields = [f.name for f in AccessLog._meta.fields]
    date_hierarchy = "created_at"


@admin.register(Site)
class SiteAdmin(admin.ModelAdmin):
    list_display = ("name", "domain", "public_key", "is_active", "created_at")
    list_filter = ("is_active",)
    search_fields = ("name", "domain", "public_key")
    readonly_fields = ("id", "public_key", "created_at", "updated_at")


@admin.register(Hit)
class HitAdmin(admin.ModelAdmin):
    list_display = ("created_at", "site", "event_type", "event_name", "path", "country_code", "device", "browser")
    list_filter = ("event_type", "device", "browser", "country_code")
    search_fields = ("path", "event_name", "referer_host", "utm_source", "utm_campaign")
    readonly_fields = [f.name for f in Hit._meta.fields]
    date_hierarchy = "created_at"
