from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class StreamProfile:
    stream_id: str
    entity_field: str
    timestamp_field: str
    categorical_fields: tuple[str, ...] = ()
    numeric_fields: tuple[str, ...] = ()


def parse_profiles(value: object) -> dict[str, StreamProfile]:
    profiles: dict[str, StreamProfile] = {}
    for item in value if isinstance(value, list) else []:
        if not isinstance(item, dict):
            continue
        stream_id = str(item.get("stream_id", "")).strip()
        entity = str(item.get("entity_field", "")).strip()
        timestamp = str(item.get("timestamp_field", "timestamp")).strip()
        if not stream_id or not entity:
            continue
        profiles[stream_id] = StreamProfile(
            stream_id, entity, timestamp,
            tuple(str(field) for field in item.get("categorical_fields", []) if field),
            tuple(str(field) for field in item.get("numeric_fields", []) if field),
        )
    return profiles
