# Path: sponsors/models/assets.py
# class GenericAsset(PolymorphicModel):
#     """
#     Base class used to add required assets to Sponsor or Sponsorship objects
#     """
#     objects = GenericAssetQuerySet.as_manager()
#     non_polymorphic = models.Manager()
# 
#     # UUID can't be the object ID because Polymorphic expects default django integer ID
#     uuid = models.UUIDField(default=uuid.uuid4, editable=False)
#     # The next 3 fields are required by Django to enable and set up generic relations
#     # pointing the asset to a Sponsor or Sponsorship object
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey("content_type", "object_id")
# 
#     # must match with internal_name from benefits configuration which describe assets
#     internal_name = models.CharField(
#         max_length=128,
#         verbose_name="Internal Name",
#         db_index=True,
#     )
# 
#     class Meta:
#         verbose_name = "Asset"
#         verbose_name_plural = "Assets"
#         unique_together = ["content_type", "object_id", "internal_name"]
#         base_manager_name = 'non_polymorphic'
# 
#     @property
#     def value(self):
#         return None
# 
#     @property
#     def is_file(self):
#         return isinstance(self.value, FileField) or isinstance(self.value, ImageFieldFile)
# 
#     @property
#     def from_sponsorship(self):
#         return self.content_type.name == "sponsorship"
# 
#     @property
#     def from_sponsor(self):
#         return self.content_type.name == "sponsor"
# 
#     @property
#     def has_value(self):
#         if self.is_file:
#             return self.value and getattr(self.value, "url", None)
#         else:
#             return bool(self.value)
# 
#     @classmethod
#     def all_asset_types(cls):
#         return cls.__subclasses__()


from rest_framework import serializers
from sponsors.models import GenericAsset
from sponsors.models.enums import PublisherChoices, LogoPlacementChoices



class LogoPlacementSerializer(serializers.Serializer):
    publisher = serializers.CharField()
    flight = serializers.CharField()
    sponsor = serializers.CharField()
    sponsor_slug = serializers.CharField()
    description = serializers.CharField()
    logo = serializers.URLField()
    start_date = serializers.DateField()
    end_date = serializers.DateField()
    sponsor_url = serializers.URLField()
    level_name = serializers.CharField()
    level_order = serializers.IntegerField()


class AssetSerializer(serializers.ModelSerializer):
    content_type = serializers.SerializerMethodField()
    value = serializers.SerializerMethodField()
    sponsor = serializers.SerializerMethodField()
    sponsor_slug = serializers.SerializerMethodField()

    class Meta:

# Path: sponsors/models/assets.py
# class GenericAsset(PolymorphicModel):
#     """
#     Base class used to add required assets to Sponsor or Sponsorship objects
#     """
#     objects = GenericAssetQuerySet.as_manager()
#     non_polymorphic = models.Manager()
# 
#     # UUID can't be the object ID because Polymorphic expects default django integer ID
#     uuid = models.UUIDField(default=uuid.uuid4, editable=False)
#     # The next 3 fields are required by Django to enable and set up generic relations
#     # pointing the asset to a Sponsor or Sponsorship object
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField()
#     content_object = GenericForeignKey("content_type", "object_id")
# 
#     # must match with internal_name from benefits configuration which describe assets
#     internal_name = models.CharField(
#         max_length=128,
#         verbose_name="Internal Name",
#         db_index=True,
#     )
# 
#     class Meta:
#         verbose_name = "Asset"
#         verbose_name_plural = "Assets"
#         unique_together = ["content_type", "object_id", "internal_name"]
#         base_manager_name = 'non_polymorphic'
# 
#     @property
#     def value(self):
#         return None
# 
#     @property
#     def is_file(self):
#         return isinstance(self.value, FileField) or isinstance(self.value, ImageFieldFile)
# 
#     @property
#     def from_sponsorship(self):
#         return self.content_type.name == "sponsorship"
# 
#     @property
#     def from_sponsor(self):
#         return self.content_type.name == "sponsor"
# 
#     @property
#     def has_value(self):
#         if self.is_file:
#             return self.value and getattr(self.value, "url", None)
#         else:
#             return bool(self.value)
# 
#     @classmethod
#     def all_asset_types(cls):
#         return cls.__subclasses__()


# Path: sponsors/serializers.py
from rest_framework import serializers
from sponsors.models import GenericAsset
from sponsors.models.enums import PublisherChoices, LogoPlacementChoices




class LogoPlacementSerializer(serializers.Serializer):
    publisher = serializers.CharField()
    flight = serializers.CharField()
    sponsor = serializers.CharField()
    sponsor_slug = serializers.CharField()
    description = serializers.CharField()
    logo = serializers.URLField()
    start_date = serializers.DateField()
    end_date = serializers.DateField()
    sponsor_url = serializers.URLField()
    level_name = serializers.CharField()
    level_order = serializers.IntegerField()


class AssetSerializer(serializers.ModelSerializer):
    content_type = serializers.SerializerMethodField()
    value = serializers.SerializerMethodField()
    sponsor = serializers.SerializerMethodField()
    sponsor_slug = serializers.SerializerMethodField()

    class Meta:

        model = GenericAsset