"""
Search domain serializers for ThrillWiki API v1.

This module contains serializers for entity search, location search,
and other search functionality.
"""

from rest_framework import serializers

from apps.core.choices.serializers import RichChoiceFieldSerializer

from ..shared import ModelChoices

# === CORE ENTITY SEARCH SERIALIZERS ===


class EntitySearchInputSerializer(serializers.Serializer):
    """Input serializer for entity search requests."""

    query = serializers.CharField(max_length=255, help_text="Search query string")
    entity_types = serializers.ListField(
        child=serializers.ChoiceField(choices=ModelChoices.get_entity_type_choices()),
        required=False,
        help_text="Types of entities to search for",
    )
    limit = serializers.IntegerField(
        default=10,
        min_value=1,
        max_value=50,
        help_text="Maximum number of results to return",
    )


class EntitySearchResultSerializer(serializers.Serializer):
    """Serializer for individual entity search results."""

    id = serializers.IntegerField()
    name = serializers.CharField()
    slug = serializers.CharField()
    type = RichChoiceFieldSerializer(choice_group="entity_types", domain="core")
    description = serializers.CharField()
    relevance_score = serializers.FloatField()

    # Context-specific info — renamed to avoid overriding Serializer.context
    context_info = serializers.JSONField(help_text="Additional context based on entity type")


class EntitySearchOutputSerializer(serializers.Serializer):
    """Output serializer for entity search results."""

    query = serializers.CharField()
    total_results = serializers.IntegerField()
    results = EntitySearchResultSerializer(many=True)
    search_time_ms = serializers.FloatField()


# === LOCATION SEARCH SERIALIZERS ===


class LocationSearchResultSerializer(serializers.Serializer):
    """Serializer for location search results."""

    display_name = serializers.CharField()
    lat = serializers.FloatField()
    lon = serializers.FloatField()
    type = serializers.CharField()
    importance = serializers.FloatField()
    address = serializers.JSONField()


class LocationSearchOutputSerializer(serializers.Serializer):
    """Output serializer for location search."""

    results = LocationSearchResultSerializer(many=True)
    query = serializers.CharField()
    count = serializers.IntegerField()


class ReverseGeocodeOutputSerializer(serializers.Serializer):
    """Output serializer for reverse geocoding."""

    display_name = serializers.CharField()
    lat = serializers.FloatField()
    lon = serializers.FloatField()
    address = serializers.JSONField()
    type = serializers.CharField()
