from rest_framework import serializers

from .models import Asset, AssetFile


class AssetFileSerializer(serializers.ModelSerializer):
    class Meta:
        model = AssetFile
        fields = [
            "id",
            "object_key",
            "bucket",
            "content_type",
            "size_bytes",
            "width",
            "height",
            "duration_ms",
            "preview_url",
            "is_primary",
        ]
        read_only_fields = fields


class AssetSerializer(serializers.ModelSerializer):
    files = AssetFileSerializer(many=True, read_only=True)

    class Meta:
        model = Asset
        fields = [
            "id",
            "name",
            "asset_type",
            "source",
            "category",
            "description",
            "metadata",
            "is_deleted",
            "files",
            "created_at",
            "updated_at",
        ]
        read_only_fields = ["id", "created_at", "updated_at"]


class AssetUploadSerializer(serializers.Serializer):
    file = serializers.FileField()
    name = serializers.CharField(max_length=255, required=False, allow_blank=True)
    asset_type = serializers.ChoiceField(choices=Asset.Type.choices)
    category = serializers.ChoiceField(choices=Asset.Category.choices, default=Asset.Category.UPLOAD)
    description = serializers.CharField(required=False, allow_blank=True)

