"""
Data types to describe the relationships between places.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, final

from betty.ancestry.date import HasDate
from betty.ancestry.has_citations import HasCitations
from betty.locale.localizable.gettext import _, ngettext
from betty.model import Entity, EntityDefinition
from betty.model.association import BidirectionalToOne, ToOneAssociate

if TYPE_CHECKING:
    from betty.ancestry.place import Place


@final
@EntityDefinition(
    "enclosure",
    label=_("Enclosure"),
    label_plural=_("Enclosures"),
    label_countable=ngettext("{count} enclosure", "{count} enclosures"),
    public_facing=False,
)
class Enclosure(HasDate, HasCitations, Entity):
    """
    .. plugin:: entity:enclosure.
    """

    encloser = BidirectionalToOne["Enclosure", "Place"](
        "betty.ancestry.place:Place",
        "enclosees",
        label=_("Encloser"),
        description=_("The place that encloses or contains the enclosee"),
    )
    """
    The outer place.
    """

    enclosee = BidirectionalToOne["Enclosure", "Place"](
        "betty.ancestry.place:Place",
        "enclosers",
        label=_("Enclosee"),
        description=_("The place that is enclosed or contained by the encloser"),
    )
    """
    The inner place.
    """

    def __init__(
        self, enclosee: ToOneAssociate[Place], encloser: ToOneAssociate[Place]
    ):
        super().__init__()
        self.enclosee = enclosee
        self.encloser = encloser
