from app.config.extensions import db

# from app.models.product import Product
from app.models.base import TimestampedMixin


class Brand(TimestampedMixin):
    """
    Represents a brand.
    """
    name = db.StringField(
        required=True,
        help_text="Name of the brand."
    )
    parent_brand = db.ReferenceField(
        'self',
        help_text="Reference to the parent brand.",
    )
    products = db.ListField(
        db.ReferenceField('Product'),
        help_text="References to the products associated with the brand.",
    )
    description = db.StringField(
        help_text="A brief description of the brand.",
    )
    logo_url = db.StringField(
        help_text="URL of the brand's logo.",
    )
    country = db.StringField(
        help_text="Country where the brand is based.",
    )
    website = db.URLField(
        help_text="Official website URL of the brand.",
    )
    founded_date = db.DateTimeField(
        help_text="Date when the brand was founded.",
    ) 
    
    meta = {
        'collection': 'brands',
        'indexes': ['public_id'] 
    }
    
    def __str__(self):
        return f"Brand: {self.name}"

    def __repr__(self):
        return f"<Brand(name={self.name})>"

    def to_dict(self):
        """
        Convert the document to a dictionary.
        """
        document_dict = super(Brand, 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

