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

# Define the channel model with examples
channel_dict = {
    'name': fields.String(
        required=True,
        description='Channel name',
        help_text="Name of the channel",
        example='CNN'
    ),
    'description': fields.String(
        description='A brief description of the channel',
        help_text="Description of the channel",
        example='A global news channel'
    ),
    'logo': fields.String(
        help_text="URL of the channel's logo",
        example='https://example.com/logo.png'
    ),
    'language': fields.String(
        help_text="Language of the channel",
        example='English'
    ),
    'country': fields.String(
        help_text="Country of the channel",
        example='United States'
    ),
    'stream_url': fields.String(
        required=True,
        description='URL for the channel\'s content feed',
        help_text="URL of the channel's feed",
        example='https://example.com/channel-feed'
    ),
    'is_active': fields.Boolean(
        description='Indicates if the channel is active or not',
        example=True
    ),
    'is_hd': fields.Boolean(
        description='Indicates whether the channel is available in high definition (HD)',
        example=False
    ),
    'website': fields.String(
        description='Website URL for the channel',
        example='https://example.com/channel-website'
    ),
    'launch_date': fields.DateTime(
        description='Date and time of the channel\'s launch or establishment',
        example='2023-11-06T12:00:00'
    ),
    'region': fields.String(
        description='Location or region where the channel primarily broadcasts',
        example='North America'
    ),
}

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

    Attributes: 
        - name (str): The name of the channel. Required.
        - description (str): A brief description of the channel.
        - logo (str): URL of the channel's logo.
        - language (str): Language of the channel.
        - country (str): Country of the channel.
        - stream_url (str): URL for the channel's content feed. Required.
        - is_active (bool): Indicates if the channel is active or not.
        - is_hd (bool): Indicates whether the channel is available in high definition (HD).
        - website (str): Website URL for the channel.
        - launch_date (datetime): Date and time of the channel's launch or establishment.
        - region (str): Location or region where the channel primarily broadcasts.
    """
 
    name = ma_fields.Str(
        required=True,
        validate=validate.Length(min=1, max=100),
        description='Channel name'
    )
    description = ma_fields.Str(
        validate=validate.Length(max=500)
    )
    logo = ma_fields.Str()
    language = ma_fields.Str()
    country = ma_fields.Str()
    stream_url = ma_fields.Str(
        required=True,
        validate=validate.URL(),
        description="URL for the channel's content feed"
    )
    is_active = ma_fields.Bool()
    is_hd = ma_fields.Bool(description='Indicates whether the channel is available in high definition (HD)')
    website = ma_fields.Url()
    launch_date = ma_fields.DateTime()
    region = ma_fields.Str()