from datetime import datetime, timezone from typing import Any, Optional from sqlalchemy import BigInteger, DateTime, ForeignKey, JSON, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.db import Base class GeneratedContract(Base): __tablename__ = "generated_contracts" id: Mapped[str] = mapped_column(String(64), primary_key=True) tenant_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True) template_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True) template_name: Mapped[str] = mapped_column(String(100), nullable=False) contract_type: Mapped[Optional[str]] = mapped_column(String(50), nullable=True) generated_by: Mapped[str] = mapped_column(String(64), nullable=False, index=True) generated_by_name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True) export_format: Mapped[str] = mapped_column(String(16), nullable=False) file_id: Mapped[Optional[str]] = mapped_column(String(64), ForeignKey("files.id"), nullable=True, index=True) file_name: Mapped[str] = mapped_column(String(255), nullable=False) mime_type: Mapped[str] = mapped_column(String(100), nullable=False) file_size: Mapped[int] = mapped_column(BigInteger, nullable=False) generated_content: Mapped[str] = mapped_column(Text, nullable=False) variable_values_json: Mapped[Optional[dict[str, str]]] = mapped_column(JSON, nullable=True) export_options_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True) file_content_base64: Mapped[str] = mapped_column(Text, nullable=False) status: Mapped[str] = mapped_column(String(32), default="generated") created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc))