"""Implementation of the CTAO DataProducts Data Model."""

from enum import EnumMeta

from . import utils
from .acquisition import Acquisition
from .ident import (
    ACADADataSource,
    ArrayElement,
    ArrayElementClass,
    DataAssociation,
    DataDivision,
    DataLevel,
    DataProcessingCategory,
    DataType,
    FacilityName,
    InstanceIdentifier,
    ProcessingSublevel,
    ProductType,
)
from .observation import (
    Atmosphere,
    Coverage,
    EnergyCoverage,
    GeodeticEarthLocation,
    Observation,
    SpaceCoverage,
    SpatialFrame,
    TimeCoverage,
    TimeReference,
    TimeRefPos,
    TimeSystem,
    TrackingCoverage,
)
from .reference import (
    Activity,
    Contact,
    Curation,
    DataModel,
    DataModelName,
    DataRights,
    ExternalDataProduct,
    ObservatoryProcess,
    Product,
    Software,
)
from .sdc import ScienceDataChallenge

# noqa: F405
__all__ = [
    "ACADADataSource",
    "Acquisition",
    "Activity",
    "ArrayElement",
    "ArrayElementClass",
    "Atmosphere",
    "Contact",
    "Coverage",
    "Curation",
    "DataAssociation",
    "DataLevel",
    "DataModel",
    "DataModelName",
    "DataProcessingCategory",
    "DataRights",
    "DataType",
    "EnergyCoverage",
    "ExternalDataProduct",
    "FacilityName",
    "GeodeticEarthLocation",
    "InstanceIdentifier",
    "Observation",
    "ProcessingSublevel",
    "Product",
    "ProductType",
    "ObservatoryProcess",
    "Software",
    "SpaceCoverage",
    "SpatialFrame",
    "TimeCoverage",
    "TimeRefPos",
    "TimeReference",
    "TimeSystem",
    "TrackingCoverage",
    "utils",
    "DataDivision",
    "ScienceDataChallenge",
]


# Fix canonical module paths for Sphinx
#
# We want all classes, enums, and enum members to appear as defined in
# this module.  Sphinx & autodoc-pydantic rely on correct __module__
# attributes to:
#   - resolve cross-references,
#   - document enum members,
#   - avoid “cannot link to itself” warnings.

for name in __all__:  # noqa: F405
    obj = globals()[name]
    obj.__module__ = __name__

    # If the object is an Enum class, fix member __module__ too.
    if isinstance(obj, EnumMeta):
        for member in obj:
            member.__module__ = __name__
