# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Critical density component."""

__all__ = ("CriticalDensity",)

from collections.abc import Callable
from typing import Any

from numpy.typing import ArrayLike, NDArray

from astropy.units import Quantity


class CriticalDensity:
    """The object has attributes and methods for the critical density."""

    critical_density0: Quantity
    """Critical density at redshift 0."""

    efunc: Callable[[Any], NDArray[Any]]

    def critical_density(self, z: Quantity | ArrayLike, /) -> Quantity:
        """Critical density in grams per cubic cm at redshift ``z``.

        Parameters
        ----------
        z : Quantity-like ['redshift'], array-like
            Input redshift.

            .. versionchanged:: 7.0
                Passing z as a keyword argument is deprecated.

            .. versionchanged:: 8.0
               z must be a positional argument.

        Returns
        -------
        rho : Quantity ['mass density']
            Critical density at each input redshift.
        """
        return self.critical_density0 * self.efunc(z) ** 2
