from flask_restx import fields
from marshmallow import Schema, fields as ma_fields, validate

# Define the program_dict
program_dict = {
    'name': fields.String(
        required=True,
        description='The name of the program.',
        example='Game of Thrones'
    ),
    'summary': fields.String(
        description='A summary or description of the program.',
        example='A fantasy drama television series.'
    ),
    'language': fields.String(
        description='Language of the program.',
        example='English'
    ),
    'genre': fields.List(
        fields.String,
        description='List of genre names associated with the program.'
    ),
    'officialSite': fields.String(
        description="The official URL of the program's page.",
        example='https://www.example.com/program'
    ),
    'program_type': fields.String(
        description='The type of the program.',
        enum=['scripted', 'reality', 'comedy', 'news'],
        example='scripted'
    ),
    'status': fields.String(
        description='The status of the program.',
        enum=['ongoing', 'ended', 'upcoming'],
        example='ongoing'
    ),
    'runtime': fields.Integer(
        description='The duration of each episode in minutes.',
        example=60
    ),
    'premiered': fields.Date(
        description='The date when the program first premiered.',
        example='2022-01-01'
    ),
    'image': fields.Nested({
        'medium': fields.String(description="URL of the medium-sized image."),
        'original': fields.String(description="URL of the original-sized image.")
    })
}

# Define the ProgramSchema
class ProgramSchema(Schema):
    """
    Schema for validating and deserializing program data.
    """

    name = ma_fields.Str(
        required=True,
        description="The name of the program.",
        validate=validate.Length(min=1, max=100)
    )

    summary = ma_fields.Str(
        description="A summary or description of the program.",
        validate=validate.Length(max=500)
    )

    language = ma_fields.Str(
        description="Language of the program."
    )

    genre = ma_fields.List(
        ma_fields.Str(),
        description="List of genre names associated with the program."
    )

    officialSite = ma_fields.Str(
        description="The official URL of the program's page."
    )

    program_type = ma_fields.Str(
        validate=validate.OneOf(['scripted', 'reality', 'comedy', 'news']),
        description="The type of the program."
    )

    status = ma_fields.Str(
        validate=validate.OneOf(['ongoing', 'ended', 'upcoming']),
        description="The status of the program."
    )

    runtime = ma_fields.Integer(
        description="The duration of each episode in minutes."
    )

    premiered = ma_fields.Date(
        description="The date when the program first premiered."
    )

    image = ma_fields.Dict(
        fields={
            'medium': ma_fields.Str(description="URL of the medium-sized image."),
            'original': ma_fields.Str(description="URL of the original-sized image.")
        }
    )
