"""
Admin Configuration for Businesses App

This module registers business models with Django admin interface.
"""

from django.contrib import admin
from .models import BusinessProfile, BusinessSearch


@admin.register(BusinessProfile)
class BusinessProfileAdmin(admin.ModelAdmin):
    """Admin interface for BusinessProfile model"""

    list_display = [
        'company_name',
        'user',
        'industry',
        'country',
        'city',
        'typical_budget_min',
        'typical_budget_max',
        'created_at'
    ]

    list_filter = ['industry', 'country', 'created_at']

    search_fields = [
        'company_name',
        'user__username',
        'user__email',
        'industry',
        'company_description'
    ]

    readonly_fields = ['created_at', 'updated_at']

    fieldsets = (
        ('Company Information', {
            'fields': ('user', 'company_name', 'company_website', 'industry', 'company_description')
        }),
        ('Contact Information', {
            'fields': ('contact_email', 'contact_phone', 'country', 'city')
        }),
        ('Budget Information', {
            'fields': ('typical_budget_min', 'typical_budget_max')
        }),
        ('Timestamps', {
            'fields': ('created_at', 'updated_at'),
            'classes': ('collapse',)
        }),
    )


@admin.register(BusinessSearch)
class BusinessSearchAdmin(admin.ModelAdmin):
    """Admin interface for BusinessSearch model"""

    list_display = [
        'id',
        'business_user',
        'budget_min',
        'budget_max',
        'top_k',
        'matches_count',
        'created_at'
    ]

    list_filter = ['created_at', 'top_k']

    search_fields = [
        'business_user__username',
        'business_user__email',
        'business_description'
    ]

    readonly_fields = [
        'business_user',
        'business_description',
        'budget_min',
        'budget_max',
        'top_k',
        'predicted_niche_probabilities',
        'predicted_popularity_probabilities',
        'matched_influencers',
        'created_at'
    ]

    def matches_count(self, obj):
        """Get number of matched influencers"""
        return len(obj.matched_influencers) if obj.matched_influencers else 0
    matches_count.short_description = 'Matches'

    def has_add_permission(self, request):
        """Disable manual creation of searches (created via API only)"""
        return False

    def has_change_permission(self, request, obj=None):
        """Make searches read-only"""
        return False
