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: int | None = 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)

    # Original final image
    final_image_path: str = Field(nullable=False)
    # Thumbnail of the original image
    final_image_thumbnail_path: str | None = Field(default=None, nullable=True)
    # Product-resized final image (width/height taken from Template table)
    final_image_product_path: str | None = Field(default=None, nullable=True)

    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},
    )
