from typing import Optional
from sqlmodel import Field, SQLModel
from datetime import datetime


class Meter(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    serial_number: str


class Measurement(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    meter_id: Optional[int] = Field(default=None, foreign_key="meter.id")
    capture_time: datetime = Field()
    voltage_phase_1: float = Field(default=0.0)
    voltage_phase_2: float = Field(default=0.0)
    voltage_phase_3: float = Field(default=0.0)
    power: float = Field(default=0.0)
    thd_1: float = Field(default=0.0)
    thd_2: float = Field(default=0.0)
    thd_3: float = 