from typing import Optional
from sqlmodel import SQLModel, Field

from entity.base import TimestampMixin


class DeviceBase(SQLModel):
    name: str
    code: str
    type: Optional[str] = None
    ip: str
    mode: int
    gas_ip: Optional[str] = None
    input_stream_url: Optional[str] = None
    output_stream_url: Optional[str] = None
    image_save_interval: Optional[int] = None
    alarm_interval: Optional[int] = None


class Device(DeviceBase, TimestampMixin, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)

    def __str__(self):
        return f"id={self.id} name={self.name} code={self.code} ip={self.ip}" \
               f" input_stream_url={self.input_stream_url} output_stream_url={self.output_stream_url}" \
               f" image_save_interval={self.image_save_interval}"


class DeviceCreate(DeviceBase):
    pass


class DeviceUpdate(DeviceBase):
    id: int
    name: Optional[str] = None
    code: Optional[str] = None
    ip: Optional[str] = None


class DeviceInfo(DeviceBase, TimestampMixin):
    id: int
    status: Optional[str] = None
    relation_scene_name: Optional[str] = None
    relation_model_names: Optional[str] = None
