from app.config.extensions import db
from app.models.base import TimestampedMixin

class Genre(TimestampedMixin):
    """
    Genre Model

    Represents a genre in the application.

    Attributes:
    - name (str): The name of the genre. Required and must be unique.
    - description (str): The description of the genre.

    Methods:
        to_dict(): Convert the document to a dictionary.
    
    Meta:
    - collection (str): Specifies the MongoDB collection name for the model.

    """
    name = db.StringField(
        required=True,  
        help_text="The name of the genre. Must be unique."
    )
    description = db.StringField(
        help_text="The description of the genre."
    )
    category = db.StringField( 
        required=True,  
        choices=["Channel", "Program"],
        help_text="The category of the genre (Channel or program)."
    )

    meta = {
        'collection': 'genres',
        'indexes': [{
                'fields': ['$name', '$description', '$category'],
                'default_language': 'english', 
        }]
    }

    def to_dict(self):
        """
        Convert the document to a dictionary.
        """ 
        document_dict = super(Genre, self).to_dict()   
        # Remove any '_cls' field
        document_dict.pop('_cls', None)
        # Remove any '_id' field
        document_dict.pop('_id', None)
        # Remove any '_id' field
        document_dict.pop('id', None)
        # replace id field with public id field
        document_dict["id"] =  document_dict.pop('public_id', None) 
        # 
        return document_dict