"""Module for date detection in text."""

from typing import List, Optional, Tuple

from src.detections.detection import Detection


class DateDetection(Detection):
    """Date detection in text.

    Eg.: 12.05.2023
    """

    TYPE_NAME = "date"

    class AnnotationPart:
        """Annotation part of date detection."""

        TWO_DIGITS_DAY = "DD"
        ONE_DIGIT_DAY = "D"
        TWO_DIGIT_MONTH = "MM"
        ONE_DIGIT_MONTH = "M"
        FOUR_DIGIT_YEAR = "YYYY"
        TWO_DIGIT_YEAR = "YY"
        TEXT_MONTH = "MMM"
        OTHER = "OTHER"

    def __init__(
        self, format: Optional[List[Tuple[AnnotationPart, str]]] = None
    ) -> None:
        """Date detection initialization.

        Args:
            format (Optional[List[Tuple[AnnotationPart, str]]], optional): Format of
                    detected date. Defaults to None.

        """
        super().__init__()

        self.format = format

    def __eq__(self, other) -> bool:
        """Compare two date detections.

        Args:
            other (DateDetection): date detection to compare with

        Returns:
            bool: true if both detections are equal, false otherwise

        """
        return self.format == other.format and super().__eq__(other)