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

class ProductImage(SQLModel, table=True):
    """
    One record per generated final image produced when a Project is created.
    Links back to the ProjectMaster and the ProductTemplate used.
    """
    __tablename__ = "product_images"

    id: Optional[int] = Field(default=None, primary_key=True)
    project_master_id: int = Field(foreign_key="project_masters.id", index=True, nullable=False)
    product_template_id: int = Field(foreign_key="product_template.id", index=True, nullable=False)

    final_image_path: str = Field(nullable=False)

    is_deleted: bool = Field(default=False)

    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(
        default_factory=datetime.utcnow,
        sa_column_kwargs={"onupdate": datetime.utcnow},
    )
