from rest_framework import serializers
from .models import Product, ProductFeature, ProductDescription, ProductImage, Category


class CategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = Category
        fields = [
            'id', 'icon', 'category_name' 
        ]

class ProductImageSerializer(serializers.ModelSerializer):
    image = serializers.ImageField(read_only=True)

    class Meta:
        model = ProductImage
        fields = ["id", "image", "is_drawing", "angle", "order"]  # [web:28]


class ProductFeatureSerializer(serializers.ModelSerializer):
    class Meta:
        model = ProductFeature
        fields = ["id", "name", "icon"]                           # [web:22]


class ProductDescriptionSerializer(serializers.ModelSerializer):
    class Meta:
        model = ProductDescription
        fields = ["housing", "diffuser", "reflector", "led", "standards"]  # [web:22]


class ProductSerializer(serializers.ModelSerializer):
    features = ProductFeatureSerializer(many=True, read_only=True)
    description = ProductDescriptionSerializer(read_only=True)
    images = ProductImageSerializer(many=True, read_only=True)
    category_data = CategorySerializer(source="category", read_only=True)

    class Meta:
        model = Product
        fields = [
            "id",
            "category",        # FK field on Product
            "name",
            "slug",
            "short_description",
            "family",
            "category_data",   # nested Category data
            "features",
            "description",
            "images",
        ]
                                           # [web:22]
