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

# Define the genre model with examples
genre_dict = {
    'name': fields.String(
        required=True,
        description='The name of the genre. Must be unique.',
        example='Comedy'
    ), 
    'category': fields.String(
        required=True,
        description='The category of the genre (Channel or program).',
        enum=['Channel', 'Program'],
        example='Channel'
    ), 
    'description': fields.String(
        description='The description of the genre',
        example='TV shows that provide humor and entertainment'
    ),
}

# Define the genre schema
class GenreSchema(Schema):
    """
    Schema for validating and deserializing genre data.

    Attributes:
        - name (str): The name of the genre. Required and must be between 1 and 100 characters.
        - description (str): The description of the genre, with a maximum of 500 characters.
        - category (str): The category of the genre, which must be either "Channel" or "Program".
    """

    name = ma_fields.Str(
        required=True,
        validate=validate.Length(min=1, max=100),
        description="The name of the genre. Required and must be between 1 and 100 characters."
    )
    
    description = ma_fields.Str(
        validate=validate.Length(max=500),
        description="The description of the genre, with a maximum of 500 characters."
    )
    
    category = ma_fields.Str(
        required=True,
        validate=validate.OneOf(["Channel", "Program"]),
        description="The category of the genre, which must be either 'Channel' or 'Program'."
    )