from django.contrib import admin

from .models import PropertyEntry, PropertyFlag, PropertySuggestion


class PropertySuggestionInline(admin.TabularInline):
    model = PropertySuggestion
    extra = 0
    readonly_fields = ("created_at",)


class PropertyFlagInline(admin.TabularInline):
    model = PropertyFlag
    extra = 0
    readonly_fields = ("created_at",)


@admin.register(PropertyEntry)
class PropertyEntryAdmin(admin.ModelAdmin):
    list_display = ("id", "address", "listing_type", "source", "has_gps_data", "flag_count", "created_at")
    list_filter = ("listing_type", "source", "has_gps_data", "is_flagged")
    search_fields = ("address", "phone", "email", "extracted_text")
    readonly_fields = ("created_at", "updated_at")
    inlines = [PropertySuggestionInline, PropertyFlagInline]


@admin.register(PropertySuggestion)
class PropertySuggestionAdmin(admin.ModelAdmin):
    list_display = ("id", "property_entry", "address", "email", "created_at")
    search_fields = ("address", "phone", "email", "note")


@admin.register(PropertyFlag)
class PropertyFlagAdmin(admin.ModelAdmin):
    list_display = ("id", "property_entry", "reason", "created_at")
    search_fields = ("reason",)
