from datetime import datetime
from typing import Optional

from sqlmodel import SQLModel, Field


class DataGasBase(SQLModel):
    device_code: str
    gas_value: float
    ts: datetime = Field(default_factory=datetime.now)

    class Config:
        json_encoders = {
            datetime: lambda v: v.strftime('%Y-%m-%d %H:%M:%S')
        }


class DataGas(DataGasBase, table=True):
    __tablename__ = 'data_gas'
    id: Optional[int] = Field(default=None, primary_key=True)


class DataGasCreate(DataGasBase):
    pass

class DataGasInfo(DataGasBase):
    id: int
    device_name: str
