"""
Park media serializers for ThrillWiki API.

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

from rest_framework import serializers

from apps.parks.models import ParkPhoto


class ParkPhotoOutputSerializer(serializers.ModelSerializer):
    """Output serializer for park photos."""

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

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


class ParkPhotoCreateInputSerializer(serializers.ModelSerializer):
    """Input serializer for creating park photos."""

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


class ParkPhotoUpdateInputSerializer(serializers.ModelSerializer):
    """Input serializer for updating park photos."""

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


class ParkPhotoListOutputSerializer(serializers.ModelSerializer):
    """Simplified output serializer for park photo lists."""

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

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


class ParkPhotoApprovalInputSerializer(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 ParkPhotoStatsOutputSerializer(serializers.Serializer):
    """Output serializer for park photo statistics."""

    total_photos = serializers.IntegerField()
    approved_photos = serializers.IntegerField()
    pending_photos = serializers.IntegerField()
    has_primary = serializers.BooleanField()
    recent_uploads = serializers.IntegerField()
