from django.db import models
from apps.accounts.models import Account
from apps.core.models import BaseModel
from apps.agencies.utils import agencies_logo_upload_path

# Create your models here.


class Agency(BaseModel):
    """
    A model that represents an agency that has a user account, a name, a description, a datetime, and a deletion status.
    
    Attributes:
        user: foreign key to the Account model that references the user account associated with the agency.
        name: character field that stores the name of the agency.
        description: A character field that stores the description of the agency.
        is_deleted: An integer field that stores the deletion status of the agency.
    
    Meta:
        verbose_name (str): Specifies the singular name for the model in the admin interface ('Agency').
        verbose_name_plural (str): Specifies the plural name for the model in the admin interface ('Agencies').
    
    Methods:
        __str__(): Returns a human-readable representation of the Agency object, displaying its name.

    """
    # Choices for the status field.
    STATUS_CHOICES = [
        ('Active', 'Active'),
        ('Inactive', 'Inactive'),
        ('Pending', 'Pending'),
    ]

    # This field can be blank or null, meaning that an agency can exist without a user account.
    # When the user account is deleted, the agency is not affected (models.DO_NOTHING).
    user = models.ForeignKey(Account, models.DO_NOTHING, blank=True, null=True)
    # This field can be blank or null, meaning that an agency can have no name.
    name = models.CharField(max_length=255, blank=True, null=True)
    # This field can be blank or null, meaning that an agency can have no description.
    description = models.CharField(max_length=255, blank=True, null=True)
    # Define an ImageField to store the logo of the TV Channel. 
    logo = models.ImageField(
        upload_to=agencies_logo_upload_path, 
        null=True,                    
        blank=True,                   
        help_text="Logo of the Agency",
        default='agencies/default_logo.png'  
    )
    # Field to store the status of the agency
    status = models.CharField(
        max_length=10, 
        choices=STATUS_CHOICES, 
        default='Active',
        help_text="Status of the Agency (e.g., Active, Inactive, Pending)."
    )

    class Meta:
        # The singular name for the model in the admin interface.
        verbose_name = "Agency" 
        # The plural name for the model in the admin interface.
        verbose_name_plural = "Agencies"
 


 
class Category(models.Model):
    name = models.CharField(max_length=255, blank=True, null=True)
    desctription = models.CharField(max_length=255, blank=True, null=True)
    def __str__(self):
        return f"{self.name}"


class Brand(BaseModel):
    """
    A model that represents a brand that has a name, an agency, a description, a category, a logo, and a status.
    Attributes:
        name: character field that stores the name of the brand.
        agency: foreign key to the Agency model that references the agency associated with the brand.
        description: character field that stores the description of the brand.
        logo: character field that stores the category of the brand.
        status: character field that stores the status of the brand.

    Meta:
        verbose_name (str): Specifies the singular name for the model in the admin interface ('Brand').
        verbose_name_plural (str): Specifies the plural name for the model in the admin interface ('Brands').
    
    Methods:
        __str__(): Returns a human-readable representation of the Brand object, displaying its name.
    """
    
    # Choices for the status field.
    STATUS_CHOICES = [
        ('Active', 'Active'),
        ('Inactive', 'Inactive'),
        ('Pending', 'Pending'),
    ]
    
    # This field can be blank or null, meaning that a brand can have no name.
    name = models.CharField(max_length=255, blank=True, null=True)
    # This field can be blank or null, meaning that a brand can belong to no agency.
    # When the agency is deleted, the brand is not affected (models.DO_NOTHING).
    agency = models.ForeignKey('Agency', models.DO_NOTHING, blank=True, null=True)
    # This field can be blank or null, meaning that a brand can have no description.
    description = models.CharField(max_length=255, blank=True, null=True)
    # This field can be blank or null, meaning that a brand can have no category.
    category = models.CharField(max_length=255, blank=True, null=True)
    # This field can be blank or null, meaning that a brand can have no logo.
    logo = models.CharField(max_length=255, blank=True, null=True)
    # This field can be blank or null, meaning that a brand can have no status.
    status = models.CharField(
        max_length=10, 
        choices=STATUS_CHOICES, 
        default='Active',
        help_text="Status of the Brand (e.g., Active, Inactive, Pending)."
    )

    class Meta:
        # The singular name for the model in the admin interface.
        verbose_name = "Brand"
        # The plural name for the model in the admin interface.
        verbose_name_plural = "Brands"


class Advertisers(BaseModel):
    """
    A model that represents an advertiser, which is a user who has a brand and a status.

    This model inherits from the BaseModel, which provides common fields and methods for all models.
    It has four fields: user, brand, status, and datetime.
    The user field is a foreign key to the Account model, which represents the user account of the advertiser.
    The brand field is a foreign key to the Brand model, which represents the brand name of the advertiser.
    The status field is a char field that stores the current status of the advertiser, such as active, inactive, or pending.
    """
    # Choices for the status field.
    STATUS_CHOICES = [
        ('Active', 'Active'),
        ('Inactive', 'Inactive'),
        ('Pending', 'Pending'),
    ]

    # Define the user field as a foreign key to the Account model
    user = models.ForeignKey(Account, models.DO_NOTHING, db_column='id_user', blank=True, null=True)
    # Define the brand field as a foreign key to the Brand model
    brand = models.ForeignKey(Brand, models.DO_NOTHING, db_column='id_brand', blank=True, null=True)
    # Define the status field as a char field with a maximum length of 255
    status = models.CharField(
        max_length=10, 
        choices=STATUS_CHOICES, 
        default='Active',
        help_text="Status of the Advertizer (e.g., Active, Inactive, Pending)."
    )

    class Meta:
        # The singular name for the model in the admin interface.
        verbose_name = "Advertizer"
        # The plural name for the model in the admin interface.
        verbose_name_plural = "Advertizers"
