# Path: sponsors/models/managers.py
# class GenericAssetQuerySet(PolymorphicQuerySet):
# 
#     def all_assets(self):
#         from sponsors.models import GenericAsset
#         classes = GenericAsset.all_asset_types()
#         return self.select_related("content_type").instance_of(*classes)


import uuid
from enum import Enum
from pathlib import Path
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db.models.fields.files import ImageFieldFile, FileField
from polymorphic.managers import PolymorphicManager
from polymorphic.models import PolymorphicModel
from sponsors.models.managers import GenericAssetQuerySet
"""
This module holds models to store generic assets
from Sponsors or Sponsorships
"""




def generic_asset_path(instance, filename):
    """
    Uses internal name + content type + obj id to avoid name collisions
    """
    directory = "sponsors-app-assets"
    ext = "".join(Path(filename).suffixes)
    name = f"{instance.uuid}"
    return f"{directory}/{name}{ext}"


class GenericAsset(PolymorphicModel):
    """
    Base class used to add required assets to Sponsor or Sponsorship objects
    """

# Path: sponsors/models/managers.py
# class GenericAssetQuerySet(PolymorphicQuerySet):
# 
#     def all_assets(self):
#         from sponsors.models import GenericAsset
#         classes = GenericAsset.all_asset_types()
#         return self.select_related("content_type").instance_of(*classes)


# Path: sponsors/models/assets.py
import uuid
from enum import Enum
from pathlib import Path
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db.models.fields.files import ImageFieldFile, FileField
from polymorphic.managers import PolymorphicManager
from polymorphic.models import PolymorphicModel
from sponsors.models.managers import GenericAssetQuerySet

"""
This module holds models to store generic assets
from Sponsors or Sponsorships
"""




def generic_asset_path(instance, filename):
    """
    Uses internal name + content type + obj id to avoid name collisions
    """
    directory = "sponsors-app-assets"
    ext = "".join(Path(filename).suffixes)
    name = f"{instance.uuid}"
    return f"{directory}/{name}{ext}"


class GenericAsset(PolymorphicModel):
    """
    Base class used to add required assets to Sponsor or Sponsorship objects
    """

    objects = GenericAssetQuerySet.as_manager()