"""
Ride media serializers for ThrillWiki API.

This module contains serializers for ride-specific media functionality.
"""

from rest_framework import serializers

from apps.rides.models import RidePhoto


class RidePhotoOutputSerializer(serializers.ModelSerializer):
    """Output serializer for ride photos."""

    uploaded_by_username = serializers.CharField(source="uploaded_by.username", read_only=True)
    file_size = serializers.ReadOnlyField()
    dimensions = serializers.ReadOnlyField()
    ride_slug = serializers.CharField(source="ride.slug", read_only=True)
    ride_name = serializers.CharField(source="ride.name", read_only=True)
    park_slug = serializers.CharField(source="ride.park.slug", read_only=True)
    park_name = serializers.CharField(source="ride.park.name", read_only=True)

    class Meta:
        model = RidePhoto
        fields = [
            "id",
            "image",
            "caption",
            "alt_text",
            "is_primary",
            "is_approved",
            "photo_type",
            "created_at",
            "updated_at",
            "date_taken",
            "uploaded_by_username",
            "file_size",
            "dimensions",
            "ride_slug",
            "ride_name",
            "park_slug",
            "park_name",
        ]
        read_only_fields = [
            "id",
            "created_at",
            "updated_at",
            "uploaded_by_username",
            "file_size",
            "dimensions",
            "ride_slug",
            "ride_name",
            "park_slug",
            "park_name",
        ]


class RidePhotoCreateInputSerializer(serializers.ModelSerializer):
    """Input serializer for creating ride photos."""

    class Meta:
        model = RidePhoto
        fields = [
            "image",
            "caption",
            "alt_text",
            "photo_type",
            "is_primary",
        ]


class RidePhotoUpdateInputSerializer(serializers.ModelSerializer):
    """Input serializer for updating ride photos."""

    class Meta:
        model = RidePhoto
        fields = [
            "caption",
            "alt_text",
            "photo_type",
            "is_primary",
        ]


class RidePhotoListOutputSerializer(serializers.ModelSerializer):
    """Simplified output serializer for ride photo lists."""

    uploaded_by_username = serializers.CharField(source="uploaded_by.username", read_only=True)

    class Meta:
        model = RidePhoto
        fields = [
            "id",
            "image",
            "caption",
            "photo_type",
            "is_primary",
            "is_approved",
            "created_at",
            "uploaded_by_username",
        ]
        read_only_fields = fields


class RidePhotoApprovalInputSerializer(serializers.Serializer):
    """Input serializer for photo approval operations."""

    photo_ids = serializers.ListField(child=serializers.IntegerField(), help_text="List of photo IDs to approve")
    approve = serializers.BooleanField(default=True, help_text="Whether to approve (True) or reject (False) the photos")


class RidePhotoStatsOutputSerializer(serializers.Serializer):
    """Output serializer for ride photo statistics."""

    total_photos = serializers.IntegerField()
    approved_photos = serializers.IntegerField()
    pending_photos = serializers.IntegerField()
    has_primary = serializers.BooleanField()
    recent_uploads = serializers.IntegerField()
    by_type = serializers.DictField(child=serializers.IntegerField(), help_text="Photo counts by type")


class RidePhotoTypeFilterSerializer(serializers.Serializer):
    """Serializer for filtering photos by type."""

    photo_type = serializers.ChoiceField(
        choices=[
            ("exterior", "Exterior View"),
            ("queue", "Queue Area"),
            ("station", "Station"),
            ("onride", "On-Ride"),
            ("construction", "Construction"),
            ("other", "Other"),
        ],
        required=False,
        help_text="Filter photos by type",
    )
