"""
Configuration file for the Sphinx documentation builder.

This file only contains a selection of the most common options. For a full
list see the documentation:
https://www.sphinx-doc.org/en/master/usage/configuration.html
"""

# -- Project information -----------------------------------------------------
# import your own package here
import ctao_datamodel

project = "ctao_datamodel"
copyright = "CTAO"
author = "CTAO Computing Department"
version = ctao_datamodel.__version__
# The full version, including alpha/beta/rc tags.
release = version


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    "sphinx.ext.githubpages",
    "sphinx.ext.intersphinx",
    "numpydoc",
    "sphinx_changelog",
    "myst_nb",
    "sphinxcontrib.autodoc_pydantic",
    "sphinx.ext.viewcode",
    "sphinx.ext.mathjax",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = []

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
    "changes",
    ".virtual_documents",  # jupyterlab cache folder that breaks build if exists.
]

# have all links automatically associated with the right domain.
default_role = "py:obj"


# intersphinx allows referencing other packages sphinx docs
intersphinx_mapping = {
    "python": ("https://docs.python.org/3/", None),
    "pydantic": ("https://docs.pydantic.dev/latest/", None),
    "astropy": ("https://docs.astropy.org/en/stable", None),
}

# -- Options for HTML output -------------------------------------------------

html_theme = "ctao"
html_theme_options = dict(
    navigation_with_keys=False,
    logo=dict(text="ctao-datamodel"),
    # setup for displaying multiple versions, also see setup in .gitlab-ci.yml
    switcher=dict(
        json_url="http://cta-computing.gitlab-pages.cta-observatory.org/common/ctao-datamodel/versions.json",  # noqa: E501
        version_match="latest" if ".dev" in version else f"v{version}",
    ),
    gitlab_url="https://gitlab.cta-observatory.org/cta-computing/common/ctao-datamodel",
    navbar_center=["version-switcher", "navbar-nav"],
    show_toc_level=3,
    header_links_before_dropdown=6,
)

# remove blank sidebars
html_sidebars = {
    "development": [],
    "reference": [],
    "models": [],
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []

# suppress module names if resolved
python_use_unqualified_type_names = True

nitpick_ignore = [
    ("py:class", "pydantic.fields.Field"),
    ("py:class", "astropy.time.core.Time"),
    ("py:obj", "ConfigDict"),
    ("py:class", "ConfigDict"),
    ("py:class", "astropydantic.time._AstropyTimePydanticTypeAnnotation"),
    ("py:obj", "uuidgen"),  # disable all py:obj missing-target warnings
    # The following is due to how sphinx-pydantic tries to document validators, which
    # doesn't work with sub-modules being imported to a higher level.
    (
        "py:obj",
        "ctao_datamodel.models.dataproducts.ident.ProductType._check_division",
    ),
    ("py:obj", "ctao_datamodel.models.dataproducts.ProductType.all*"),
    ("py:class", "astropydantic.unit.AstroPydanticUnit"),
    (
        "py:obj",
        "ctao_datamodel.models.dataproducts.observation.TimeCoverage._check_if_reference_is_needed",
    ),
    (
        "py:obj",
        "ctao_datamodel.models.dataproducts.ident.ACADADataSource._parse_from_string",
    ),
    (
        "py:obj",
        "ctao_datamodel.models.dataproducts.ident.InstanceIdentifier._check_lunar_cycle_id",
    ),
    (
        "py:obj",
        "ctao_datamodel.models.dataproducts.reference.Product._check_simulation",
    ),
]

add_module_names = False

python_use_unqualified_names = True
python_display_short_signature = True

# in case the kernel is saved in the ipynb file, map the default kernel name to blank
nb_kernel_rgx_aliases = {"ctao-datamodel": ""}

# prevent StrEnums from raising hundreds of warnings, but causes them not to be
# well documented:
numpydoc_show_class_members = False

# Prevent warnings for things like AstroPydanticTime. Note this config name is
# wrong in the docs, where it is called
# autodoc_pydantic_settings_show_json_error_strategy, but setting that has no
# effect
autodoc_pydantic_model_show_json_error_strategy = "coerce"

# Some cleanups for other autodoc options
autodoc_pydantic_settings_hide_paramlist = True
autodoc_pydantic_model_undoc_members = True
autodoc_pydantic_model_show_enum_members = True

# This prevents a bug in autodoc_pydantic for models with validators on all
# fields. It tries to link to "Model.all fields", which is obviously wrong. Can
# remove this when that bug is fixed. See
# https://github.com/mansenfranzen/autodoc_pydantic/issues/321
autodoc_pydantic_model_show_validator_summary = False


myst_enable_extensions = [
    "amsmath",
    "colon_fence",
    "deflist",
    "dollarmath",
    "html_image",
]
