from datetime import datetime, timedelta


# ===== Time-Indexed Data Segment =====
class DataSegment:
    # ===== Lifecycle =====
    def __init__(
        self,
        full_data: list[float],
        start_time: datetime,
        start_index: int,
        end_index: int,
    ):
        if not isinstance(start_index, int):
            raise TypeError("start_index must be an integer")
        if not isinstance(end_index, int):
            raise TypeError("end_index must be an integer")
        """
        full_data: The complete list of sensor readings.
        start_time: The timestamp of the very first reading in full_data.
        start_index: The offset (in seconds) from start_time to the beginning of this segment.
        end_index: The offset (in seconds) from start_time to the end of this segment.
        """
        self.full_data = full_data
        self._base_start_time = start_time
        self._start_index = start_index
        self._end_index = end_index
        self.chamber = ""
        self.notes = ""

    # ===== Index Properties =====
    @property
    def start_index(self) -> int:
        return self._start_index

    @start_index.setter
    def start_index(self, value: int):
        self._start_index = value

    @property
    def end_index(self) -> int:
        return self._end_index

    @end_index.setter
    def end_index(self, value: int):
        self._end_index = value

    # ===== Derived Time Properties =====
    @property
    def start_time(self) -> datetime:
        return self._base_start_time + timedelta(seconds=self.start_index)

    @property
    def end_time(self) -> datetime:
        return self._base_start_time + timedelta(seconds=self.end_index)
