from sqlmodel import SQLModel
from sqlmodel import Field, Relationship
from sqlalchemy import String
from sqlalchemy.sql.schema import Column
from typing import TYPE_CHECKING, Optional, List

if TYPE_CHECKING:
    from app.src.models.product import ProductRead
    from app.src.models.product import Product


class ProductTypeBase(SQLModel):
    name: str
    description: str


class ProductType(ProductTypeBase, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str = Field(sa_column=Column("name", String, unique=True))
    description: Optional[str] = Field(default=None)
    products: List["Product"] = Relationship(back_populates="product_type")


class ProductTypeReadwithProduct(ProductTypeBase):
    product_type: Optional["ProductRead"] = None


class ProductTypeCreate(ProductTypeBase):
    pass


class ProductTypeRead(ProductTypeBase):
    id: int


# Nel modello update tutti gli attributi devono essere opzionali
class ProductTypeUpdate(SQLModel):
    name: Optional[str] = None
    description: Optional[str] = None

sqlalchemy.sql.schema.Column sqlmodel.Field sqlmodel.Relationship
[((452, 489), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (457, 489), False, 'from sqlmodel import Field, Relationship\n'), ((592, 611), 'sqlmodel.Field', 'Field', ([], {'default': 'None'}), '(default=None)\n', (597, 611), False, 'from sqlmodel import Field, Relationship\n'), ((644, 687), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""product_type"""'}), "(back_populates='product_type')\n", (656, 687), False, 'from sqlmodel import Field, Relationship\n'), ((522, 557), 'sqlalchemy.sql.schema.Column', 'Column', (['"""name"""', 'String'], {'unique': '(True)'}), "('name', String, unique=True)\n", (528, 557), False, 'from sqlalchemy.sql.schema import Column\n')]