# analytics/admin.py
from django.contrib import admin
from .models import Insight, Notification, StockForecast, RolePermission


@admin.register(Insight)
class InsightAdmin(admin.ModelAdmin):
    list_display = ('company', 'title', 'category', 'priority', 'color', 'is_read', 'created_at')
    list_filter = ('category', 'priority', 'is_read', 'company')
    search_fields = ('title', 'description', 'company__name')
    date_hierarchy = 'created_at'
    readonly_fields = ('created_at',)


@admin.register(Notification)
class NotificationAdmin(admin.ModelAdmin):
    list_display = ('company', 'title', 'notification_type', 'is_read', 'created_at')
    list_filter = ('notification_type', 'is_read', 'company')
    search_fields = ('title', 'message', 'company__name')


@admin.register(StockForecast)
class StockForecastAdmin(admin.ModelAdmin):
    list_display = ('company', 'product', 'stock_health', 'days_until_stockout', 'avg_daily_sales', 'recommended_restock_qty', 'generated_at')
    list_filter = ('stock_health', 'company')
    search_fields = ('product__name', 'company__name')


@admin.register(RolePermission)
class RolePermissionAdmin(admin.ModelAdmin):
    list_display = ('company', 'role', 'can_reverse_orders', 'can_view_analytics', 'can_export_data')
    list_filter = ('role', 'company')
    search_fields = ('company__name',)
