# serializers.py

#小程序弹窗序列化器
from rest_framework import serializers
from peizhi.models import PopupPage, PopupConfig, PopupImage

class PopupImageSerializer(serializers.ModelSerializer):
    """图片序列化器（输出用）"""
    class Meta:
        model = PopupImage
        fields = ['id', 'image_url', 'text', 'sort_order']


class PopupConfigSerializer(serializers.ModelSerializer):
    """弹窗配置序列化器（输出用）"""
    images = PopupImageSerializer(many=True, read_only=True)

    class Meta:
        model = PopupConfig
        fields = [
            'id', 'popup_id', 'title', 'description',
            'strategy_type', 'max_count', 'reset_interval',
            'duration', 'force_even_muted', 'sort_order',
            'is_active', 'start_time', 'end_time',
            'created_at', 'updated_at', 'images'
        ]


class PopupPageSerializer(serializers.ModelSerializer):
    """页面序列化器（输出用）"""
    popups = PopupConfigSerializer(many=True, read_only=True)

    class Meta:
        model = PopupPage
        fields = [
            'id', 'page_key', 'name', 'description',
            'is_active', 'ignore_user_mute',
            'created_at', 'updated_at', 'popups'
        ]