from dataclasses import dataclass
from pathlib import Path
from typing import List, NamedTuple, Optional

import numpy as np


class ObjectDetectionMoment(NamedTuple):
    """
    Represents input data for object detection processing.
    file_path: path to the file which will be processed
    timestamp: timestamp of the video when object is detected
    """

    file_path: Path
    timestamp: float


class DetectedObject(NamedTuple):
    """
    Represents a detected object after object detection processing.
    label: label of the detected object (e.g. person, car, etc.)
    confidence: confidence of the detected object
    """

    label: str
    confidence: float

    def __str__(self):
        return f"{self.label} ({self.confidence * 100:.2f}%)"


class DetectedObjectsData(NamedTuple):
    """
    Stores detected objects information and related image with drawn bounding boxes.
    image: image with drawn bounding boxes
    objects: list of detected objects
    """

    image: Optional[np.ndarray]
    objects: List[DetectedObject]


@dataclass
class ObjectDetectionResult:
    """
    Represents the result of work of object detection processing module.
    file_path: path to the file which was processed
    objects_data: detected objects data
    """

    file_path: Path
    objects_data: DetectedObjectsData
