"""Pass 1: Even distribution service for telemetry generation.

Creates baseline telemetry DataFrame with equal values for all elements.
"""

from datetime import datetime
from typing import List

import polars as pl


class EvenDistributionService:
    """Creates base telemetry with even distribution across all elements.

    Single responsibility: Generate initial DataFrame where all elements
    have identical unit_value at each timestamp.
    """

    def generate_base_telemetry(
        self,
        timestamps: List[datetime],
        elements: List[str],
        typical_hourly_volume: float
    ) -> pl.DataFrame:
        """Generate base telemetry with even distribution.

        Args:
            timestamps: List of hourly timestamps
            elements: List of element IDs
            typical_hourly_volume: Base unit value for all elements

        Returns:
            DataFrame with columns: timestamp, element_id, unit_value
            Every element has unit_value = typical_hourly_volume at each timestamp
        """
        if not timestamps or not elements:
            return pl.DataFrame({
                "timestamp": [],
                "element_id": [],
                "unit_value": []
            })

        # Build records using cross product of timestamps and elements
        records = []
        for timestamp in timestamps:
            for element_id in elements:
                records.append({
                    "timestamp": timestamp,
                    "element_id": element_id,
                    "unit_value": typical_hourly_volume,
                })

        return pl.DataFrame(records)
