from django.db import models

from apps.master.managers import master_manager
from apps.master.managers.master_manager import ContactUsRequestTypeMasterManager
from base.documents_path import DocumentsPath
from base.models import BaseModel


class CountryMaster(BaseModel):
    """
    This is the CountryMaster model.
    It represents countries in the system.

    Attributes:
        name (str): The name of the country (maximum length 150 characters).

    Meta Options:
        db_table (str): The database table name for this model.

    Methods:
        __str__(): Returns a string representation of the country.
    """

    name = models.CharField(max_length=150, null=False, blank=False, unique=True)

    # Custom manager for CountryMaster
    objects = master_manager.CountryManager()

    def __str__(self):
        return f"{self.name}"

    class Meta:
        db_table = "country_master"


class StateMaster(BaseModel):
    """
    This is the StateMaster model.
    It represents states in the system.

    Attributes:
        name (str): The name of the state (maximum length 150 characters).

    Meta Options:
        db_table (str): The database table name for this model.

    Methods:
        __str__(): Returns a string representation of the state.
    """

    name = models.CharField(max_length=150, null=False, blank=False, unique=True)

    # Custom manager for CityMaster
    objects = master_manager.StateManager()

    def __str__(self):
        return f"{self.name}"

    class Meta:
        db_table = "state_master"


class CityMaster(BaseModel):
    """
    This is the CityMaster model.
    It represents cities in the system.

    Attributes:
        name (str): The name of the city (maximum length 150 characters).

    Meta Options:
        db_table (str): The database table name for this model.

    Methods:
        __str__(): Returns a string representation of the city.
    """

    name = models.CharField(max_length=150, null=False, blank=False, unique=True)

    # Custom manager for CityMaster
    objects = master_manager.CityManager()

    def __str__(self):
        return f"{self.name}"

    class Meta:
        db_table = "city_master"


class NetworkOperatorMaster(BaseModel):
    """
    This is the NetworkOperatorMaster model. It represents a network operator in the system.

    Attributes:
        name (str): The name of the network operator.
        phone (str): The phone number of the network operator.
        url (UrlField): A URL associated with the network operator.
        logo (FileField): An image representing the network operator.
        type_id (int): An identity for scraping data.

    Meta Options:
        db_table (str): The database table name for this model.

    Methods:
        __str__(): Returns a string representation of the network operator.
    """

    name = models.CharField(null=False, blank=False, unique=True)
    phone = models.CharField(null=True, blank=True)
    url = models.URLField(null=True, blank=True)
    logo = models.FileField(
        upload_to=DocumentsPath.get_network_operator_path, null=True
    )
    type_id = models.IntegerField(null=True, blank=True)

    # Custom manager for NetworkOperatorMaster
    objects = master_manager.NetworkOperatorManager()

    def __str__(self):
        return f"{self.name}"

    class Meta:
        db_table = "network_operator"


class ConnectorMaster(BaseModel):
    """
    This is the ConnectorMaster model.
    It represents connectors (plugs) in the system.

    Attributes:
        name (str): The name of the connector
        short_name (str): The short name of the connector
        image (FileField): An image representing the connector.
        type_id (int): An identity of scar data

    Meta Options:
        db_table (str): The database table name for this model.

    Methods:
        __str__(): Returns a string representation of the connector.
    """

    name = models.CharField(null=False, blank=False, unique=True)
    short_name = models.CharField(null=False, blank=False)
    image = models.FileField(upload_to=DocumentsPath.get_connector_path, null=True)
    type_id = models.IntegerField(null=True, blank=True)

    # Custom manager for ConnectorMaster
    objects = master_manager.ConnectorManager()

    def __str__(self):
        return f"{self.name}"

    class Meta:
        db_table = "connector_master"


class LocationMaster(BaseModel):
    """
    This is the LocationMaster model.
    It represents locations in the system.

    Attributes:
        name (str): The name of the location (maximum length 150 characters).
        type_id (str): An identity of scar data

    Meta Options:
        db_table (str): The database table name for this model.

    Methods:
        __str__(): Returns a string representation of the location.
    """

    name = models.CharField(null=False, blank=False, unique=True)
    type_id = models.CharField(null=True, blank=True)

    # Custom manager for LocationMaster
    objects = master_manager.LocationManager()

    def __str__(self):
        return f"{self.name}"

    class Meta:
        db_table = "location_master"


class AmenitiesMaster(BaseModel):
    """
    This is the AmenitiesMaster model.
    It represents amenities in the system.

    Attributes:
        name (str): The name of the amenities
        type_id (int): An identity of scarp data

    Meta Options:
        db_table (str): The database table name for this model.

    Methods:
        __str__(): Returns a string representation of the amenities.
    """

    name = models.CharField(null=False, blank=False, unique=True)
    type_id = models.IntegerField(null=True, blank=True)

    # Custom manager for AmenitiesMaster
    objects = master_manager.AmenitiesManager()

    def __str__(self):
        return f"{self.name}"

    class Meta:
        db_table = "amenities_master"


class RatingLabelMaster(BaseModel):
    """
    This is the RatingLabelMaster model.
    It represents label for ratings in the system.

    Attributes:
        label (str): The label of the rating.

    Meta Options:
        db_table (str): The database table name for this model.

    Methods:
        __str__(): Returns a string representation of the label.
    """

    label = models.CharField(null=False, blank=False, unique=True)

    # Custom manager for RatingLabelMaster
    objects = master_manager.RatingLabelManager()

    def __str__(self):
        return f"{self.label}"

    class Meta:
        db_table = "rating_label_master"


class RatingLabelsAsset(BaseModel):
    """
    This is the RatingLabelsAsset model.
    It represents assets labeled based on ratings.

    Attributes:
        rating (int): The numeric rating associated with the asset (non-null, non-blank).
        title (str): The title of rating asset
        labels (ManyToManyField): The labels associated with the asset (non-null, non-blank).
        asset (FileField): The file representing the asset.

    Meta Options:
        db_table (str): The database table name for this model.

    Note:
        - `AssetTypeConstants` is used for the choices in the `asset_type` field.
    """

    rating = models.FloatField(null=True)
    title = models.CharField(null=False, blank=False)
    labels = models.ManyToManyField(
        RatingLabelMaster, related_name="rating_label_assets"
    )
    asset = models.FileField(
        upload_to=DocumentsPath.get_rating_label_path,
    )

    # Custom manager for RatingLabelsAsset
    objects = master_manager.RatingLabelsAssetManager()

    class Meta:
        db_table = "rating_labels_asset"


class PrivacyPolicyMaster(BaseModel):
    """
    This is the PrivacyPolicyMaster model.
    It represents content for PrivacyPolicy

    Attributes:
        content (str): Content for PrivacyPolicy

    Meta Options:
        db_table (str): The database table name for this model.
    """

    content = models.TextField()

    # Custom manager for PrivacyPolicyMaster
    objects = master_manager.PrivacyPolicyManager()

    class Meta:
        db_table = "privacy_policy_master"


class TermsOfUseMaster(BaseModel):
    """
    This is the TermsOfUseMaster model.
    It represents TermsOfUse content.

    Attributes:
        content (content): Content for TermsOfUse

    Meta Options:
        db_table (str): The database table name for this model.
    """

    content = models.TextField()

    # Custom manager for TermsOfUseMaster
    objects = master_manager.TermsOfUseMasterManager()

    class Meta:
        db_table = "terms_of_user_master"


class InsuranceCompanyMaster(BaseModel):
    """
    Model class for representing insurance companies.

    This model represents InsuranceCompanyMaster instances with a 'name' field.

    Attributes:
        name (str): The name of the insurance company.
        objects: Custom manager for querying InsuranceCompanyMaster instances.
    """

    name = models.CharField(unique=True)

    # Custom manager for InsuranceCompanyMaster
    objects = master_manager.InsuranceCompanyMasterManager()

    class Meta:
        db_table = "insurance_company_master"


class InsuranceTypeMaster(BaseModel):
    """
    Model class for representing insurance types.

    This model represents InsuranceTypeMaster instances with 'name' and 'insurance_company' fields.

    Attributes:
        name (str): The name of the insurance type.
        insurance_company: ForeignKey to InsuranceCompanyMaster, establishing a relationship.
        objects: Custom manager for querying InsuranceTypeMaster instances.
    """

    name = models.CharField()
    insurance_company = models.ForeignKey(
        InsuranceCompanyMaster,
        on_delete=models.CASCADE,
        related_name="insurance_company_types",
    )

    # Custom manager for InsuranceTypeMaster
    objects = master_manager.InsuranceTypeMasterManager()

    class Meta:
        db_table = "insurance_type_master"


class FaqMaster(BaseModel):
    """
    This is the FaqMaster model.
    It represents FaqMaster content.

    Attributes:
        content (content): title for FaqMaster
        content (content): Content for FaqMaster

    Meta Options:
        db_table (str): The database table name for this model.
    """

    title = models.TextField()
    content = models.TextField()

    # Custom manager for FaqMaster
    objects = master_manager.FaqMasterManager()

    class Meta:
        db_table = "faq_master"


class ContactUsRequestTypeMaster(BaseModel):
    """
    Model class for representing contact request types.

    This model represents different types of contact requests.

    Attributes:
        name (str): Name of the contact request type.
        objects (ContactUsRequestTypeMasterManager): Custom manager for querying ContactUsRequestTypeMaster instances.
    """

    name = models.TextField(unique=True)

    objects = ContactUsRequestTypeMasterManager()

    class Meta:
        """
        Meta class to specify database table name.
        """

        db_table = "contact_us_request_type_master"
