# Path: sponsors/models/assets.py
# class ImgAsset(GenericAsset):
#     image = models.ImageField(
#         upload_to=generic_asset_path,
#         blank=False,
#         null=True,
#     )
# 
#     def __str__(self):
#         return f"Image asset: {self.internal_name}"
# 
#     class Meta:
#         verbose_name = "Image Asset"
#         verbose_name_plural = "Image Assets"
# 
#     @property
#     def value(self):
#         return self.image
# 
#     @value.setter
#     def value(self, value):
#         self.image = value
# 
# class TextAsset(GenericAsset):
#     text = models.TextField(default="")
# 
#     def __str__(self):
#         return f"Text asset: {self.internal_name}"
# 
#     class Meta:
#         verbose_name = "Text Asset"
#         verbose_name_plural = "Text Assets"
# 
#     @property
#     def value(self):
#         return self.text
# 
#     @value.setter
#     def value(self, value):
#         self.text = value
# 
# class FileAsset(GenericAsset):
#     file = models.FileField(
#         upload_to=generic_asset_path,
#         blank=False,
#         null=True,
#     )
# 
#     def __str__(self):
#         return f"File asset: {self.internal_name}"
# 
#     class Meta:
#         verbose_name = "File Asset"
#         verbose_name_plural = "File Assets"
# 
#     @property
#     def value(self):
#         return self.file
# 
#     @value.setter
#     def value(self, value):
#         self.file = value
# 
# class ResponseAsset(GenericAsset):
#     response = models.CharField(
#         max_length=32, choices=Response.choices(), blank=False, null=True
#     )
# 
#     def __str__(self):
#         return f"Response Asset: {self.internal_name}"
# 
#     class Meta:
#         verbose_name = "Response Asset"
#         verbose_name_plural = "Response Assets"
# 
#     @property
#     def value(self):
#         return self.response
# 
#     @value.setter
#     def value(self, value):
#         self.response = value
# 
# class Response(Enum):
#     YES = "Yes"
#     NO = "No"
# 
#     @classmethod
#     def choices(cls):
#         return tuple((i.name, i.value) for i in cls)
# 
# Path: sponsors/models/managers.py
# class BenefitFeatureQuerySet(PolymorphicQuerySet):
# 
#     def delete(self):
#         if not self.polymorphic_disabled:
#             return self.non_polymorphic().delete()
#         else:
#             return super().delete()
# 
#     def from_sponsorship(self, sponsorship):
#         return self.filter(sponsor_benefit__sponsorship=sponsorship).select_related("sponsor_benefit__sponsorship")
# 
#     def required_assets(self):
#         from sponsors.models.benefits import RequiredAssetMixin
#         required_assets_classes = RequiredAssetMixin.__subclasses__()
#         return self.instance_of(*required_assets_classes).select_related("sponsor_benefit__sponsorship")
# 
#     def provided_assets(self):
#         from sponsors.models.benefits import ProvidedAssetMixin
#         provided_assets_classes = ProvidedAssetMixin.__subclasses__()
#         return self.instance_of(*provided_assets_classes).select_related("sponsor_benefit__sponsorship")


from django import forms
from django.db import models
from django.db.models import UniqueConstraint
from django.urls import reverse
from polymorphic.models import PolymorphicModel
from sponsors.models.assets import ImgAsset, TextAsset, FileAsset, ResponseAsset, Response
from sponsors.models.enums import (
    PublisherChoices,
    LogoPlacementChoices,
    AssetsRelatedTo,
)
from sponsors.models.managers import BenefitFeatureQuerySet
    It's a mixin to updates the benefit feature creation to also
    create the related assets models
    """

    def create_benefit_feature(self, sponsor_benefit, **kwargs):
        if not self.ASSET_CLASS:
            raise NotImplementedError(
                "Subclasses of AssetConfigurationMixin must define an ASSET_CLASS attribute.")

        # Super: BenefitFeatureConfiguration.create_benefit_feature
        benefit_feature = super().create_benefit_feature(sponsor_benefit, **kwargs)

        content_object = sponsor_benefit.sponsorship
        if self.related_to == AssetsRelatedTo.SPONSOR.value:
            content_object = sponsor_benefit.sponsorship.sponsor

        asset_qs = content_object.assets.filter(internal_name=self.internal_name)
        if not asset_qs.exists():
            asset = self.ASSET_CLASS(
                content_object=content_object, internal_name=self.internal_name,
            )
            asset.save()

        return benefit_feature

    class Meta:
        abstract = True


class BaseRequiredImgAsset(BaseRequiredAsset):

# Path: sponsors/models/assets.py
# class ImgAsset(GenericAsset):
#     image = models.ImageField(
#         upload_to=generic_asset_path,
#         blank=False,
#         null=True,
#     )
# 
#     def __str__(self):
#         return f"Image asset: {self.internal_name}"
# 
#     class Meta:
#         verbose_name = "Image Asset"
#         verbose_name_plural = "Image Assets"
# 
#     @property
#     def value(self):
#         return self.image
# 
#     @value.setter
#     def value(self, value):
#         self.image = value
# 
# class TextAsset(GenericAsset):
#     text = models.TextField(default="")
# 
#     def __str__(self):
#         return f"Text asset: {self.internal_name}"
# 
#     class Meta:
#         verbose_name = "Text Asset"
#         verbose_name_plural = "Text Assets"
# 
#     @property
#     def value(self):
#         return self.text
# 
#     @value.setter
#     def value(self, value):
#         self.text = value
# 
# class FileAsset(GenericAsset):
#     file = models.FileField(
#         upload_to=generic_asset_path,
#         blank=False,
#         null=True,
#     )
# 
#     def __str__(self):
#         return f"File asset: {self.internal_name}"
# 
#     class Meta:
#         verbose_name = "File Asset"
#         verbose_name_plural = "File Assets"
# 
#     @property
#     def value(self):
#         return self.file
# 
#     @value.setter
#     def value(self, value):
#         self.file = value
# 
# class ResponseAsset(GenericAsset):
#     response = models.CharField(
#         max_length=32, choices=Response.choices(), blank=False, null=True
#     )
# 
#     def __str__(self):
#         return f"Response Asset: {self.internal_name}"
# 
#     class Meta:
#         verbose_name = "Response Asset"
#         verbose_name_plural = "Response Assets"
# 
#     @property
#     def value(self):
#         return self.response
# 
#     @value.setter
#     def value(self, value):
#         self.response = value
# 
# class Response(Enum):
#     YES = "Yes"
#     NO = "No"
# 
#     @classmethod
#     def choices(cls):
#         return tuple((i.name, i.value) for i in cls)
# 
# Path: sponsors/models/managers.py
# class BenefitFeatureQuerySet(PolymorphicQuerySet):
# 
#     def delete(self):
#         if not self.polymorphic_disabled:
#             return self.non_polymorphic().delete()
#         else:
#             return super().delete()
# 
#     def from_sponsorship(self, sponsorship):
#         return self.filter(sponsor_benefit__sponsorship=sponsorship).select_related("sponsor_benefit__sponsorship")
# 
#     def required_assets(self):
#         from sponsors.models.benefits import RequiredAssetMixin
#         required_assets_classes = RequiredAssetMixin.__subclasses__()
#         return self.instance_of(*required_assets_classes).select_related("sponsor_benefit__sponsorship")
# 
#     def provided_assets(self):
#         from sponsors.models.benefits import ProvidedAssetMixin
#         provided_assets_classes = ProvidedAssetMixin.__subclasses__()
#         return self.instance_of(*provided_assets_classes).select_related("sponsor_benefit__sponsorship")


# Path: sponsors/models/benefits.py
from django import forms
from django.db import models
from django.db.models import UniqueConstraint
from django.urls import reverse
from polymorphic.models import PolymorphicModel
from sponsors.models.assets import ImgAsset, TextAsset, FileAsset, ResponseAsset, Response
from sponsors.models.enums import (
    PublisherChoices,
    LogoPlacementChoices,
    AssetsRelatedTo,
)
from sponsors.models.managers import BenefitFeatureQuerySet

    It's a mixin to updates the benefit feature creation to also
    create the related assets models
    """

    def create_benefit_feature(self, sponsor_benefit, **kwargs):
        if not self.ASSET_CLASS:
            raise NotImplementedError(
                "Subclasses of AssetConfigurationMixin must define an ASSET_CLASS attribute.")

        # Super: BenefitFeatureConfiguration.create_benefit_feature
        benefit_feature = super().create_benefit_feature(sponsor_benefit, **kwargs)

        content_object = sponsor_benefit.sponsorship
        if self.related_to == AssetsRelatedTo.SPONSOR.value:
            content_object = sponsor_benefit.sponsorship.sponsor

        asset_qs = content_object.assets.filter(internal_name=self.internal_name)
        if not asset_qs.exists():
            asset = self.ASSET_CLASS(
                content_object=content_object, internal_name=self.internal_name,
            )
            asset.save()

        return benefit_feature

    class Meta:
        abstract = True


class BaseRequiredImgAsset(BaseRequiredAsset):

    ASSET_CLASS = ImgAsset