"""Shared base for vendor-SDK drivers (tier=sdk) and ML sources (tier=ml)."""

from __future__ import annotations

from ..core.source import Source, StreamSpec


class DriverSource(Source):
    """
    A Source built from a catalog `Device`. Subclasses implement `read()` using the
    vendor SDK; the StreamSpec (name/type/channels/rate) comes straight from the
    catalog so every driver publishes a consistent, labelled LSL stream.

    Device-specific connection params (serial_port, ip_address, camera, ...) arrive
    as kwargs and are stored on `self.opts` for the subclass to use.
    """

    def __init__(self, device, *, source_id_suffix: str = "", **opts):
        self.device = device
        self.opts = opts
        super().__init__(StreamSpec(
            name=device.stype or device.modality.upper(),
            stype=device.stype or device.modality.upper(),
            channels=list(device.channels) or [device.modality],
            nominal_srate=float(device.srate),
            channel_format="float32",
            source_id=f"{device.slug}{source_id_suffix}",
        ))

    def read(self):
        raise NotImplementedError(
            f"{type(self).__name__} needs the {self.device.brand} hardware + SDK. "
            f"See HARDWARE.md / notes: {self.device.notes!r}")
