from django.contrib import admin
from .models import NginxSettings, NginxAlertProfile, NginxAccessLog, IPGeoCache, ThreatAlert


@admin.register(NginxSettings)
class NginxSettingsAdmin(admin.ModelAdmin):
    list_display = ['namespace', 'pod_label', 'container', 'fetch_interval_seconds',
                    'log_file_path', 'enabled', 'last_fetch_at']


@admin.register(NginxAlertProfile)
class NginxAlertProfileAdmin(admin.ModelAdmin):
    list_display = ['name', 'alert_window_seconds', 'alert_max_requests',
                    'alert_max_error_rate', 'enabled', 'created_at']
    list_filter = ['enabled']


@admin.register(NginxAccessLog)
class NginxAccessLogAdmin(admin.ModelAdmin):
    list_display = ['timestamp', 'remote_addr', 'method', 'request_uri', 'status',
                    'request_time', 'service', 'country', 'city']
    list_filter = ['status', 'service', 'country']
    search_fields = ['remote_addr', 'request_uri', 'request_id']
    readonly_fields = ['timestamp', 'request_id']
    date_hierarchy = 'timestamp'


@admin.register(IPGeoCache)
class IPGeoCacheAdmin(admin.ModelAdmin):
    list_display = ['ip', 'country', 'city', 'isp', 'is_private', 'fetched_at']
    search_fields = ['ip', 'country', 'city']


@admin.register(ThreatAlert)
class ThreatAlertAdmin(admin.ModelAdmin):
    list_display = ['detected_at', 'remote_addr', 'alert_type', 'profile',
                    'request_count', 'error_count', 'country', 'notified', 'dismissed']
    list_filter = ['alert_type', 'dismissed', 'notified', 'profile']
    search_fields = ['remote_addr', 'country']
