from typing import Optional

from sqlmodel import Field, SQLModel


class MagicPlanPlanModel(SQLModel, table=True):
    __tablename__ = "magic_plan_plan"

    id: Optional[int] = Field(default=None, primary_key=True)
    magic_plan_uid: Optional[str] = Field(default=None, unique=True, index=True)
    name: Optional[str] = None
    address: Optional[str] = None
    postcode: Optional[str] = None


class MagicPlanFloorModel(SQLModel, table=True):
    __tablename__ = "magic_plan_floor"

    id: Optional[int] = Field(default=None, primary_key=True)
    magic_plan_plan_id: int = Field(foreign_key="magic_plan_plan.id")
    level: Optional[int] = None


class MagicPlanRoomModel(SQLModel, table=True):
    __tablename__ = "magic_plan_room"

    id: Optional[int] = Field(default=None, primary_key=True)
    magic_plan_floor_id: int = Field(foreign_key="magic_plan_floor.id")
    name: Optional[str] = None
    width_m: Optional[float] = None
    length_m: Optional[float] = None
    area_m2: Optional[float] = None


class MagicPlanWindowModel(SQLModel, table=True):
    __tablename__ = "magic_plan_window"

    id: Optional[int] = Field(default=None, primary_key=True)
    magic_plan_room_id: int = Field(foreign_key="magic_plan_room.id")
    width_m: Optional[float] = None
    height_m: Optional[float] = None
    area_m2: Optional[float] = None
    opening_type: Optional[str] = None


class MagicPlanDoorModel(SQLModel, table=True):
    __tablename__ = "magic_plan_door"

    id: Optional[int] = Field(default=None, primary_key=True)
    magic_plan_room_id: int = Field(foreign_key="magic_plan_room.id")
    width_mm: Optional[float] = None
    type: Optional[str] = None
