from datetime import datetime from sqlalchemy import DateTime, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.core.constants import ActorValue from app.core.database import Base from app.modules.approvals.constants import ApprovalStatus class ApprovalRequest(Base): __tablename__ = "approval_requests" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) ticket_id: Mapped[str] = mapped_column(String(64), unique=True, index=True) domain: Mapped[str] = mapped_column(String(128), index=True) record_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True) action: Mapped[str] = mapped_column(String(128), index=True) applicant: Mapped[str] = mapped_column(String(128), default=ActorValue.API, index=True) approver: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True) status: Mapped[str] = mapped_column(String(32), default=ApprovalStatus.PENDING, index=True) reason: Mapped[str | None] = mapped_column(Text, nullable=True) payload: Mapped[str | None] = mapped_column(Text, nullable=True) decision_comment: Mapped[str | None] = mapped_column(Text, nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True) updated_at: Mapped[datetime] = mapped_column( DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, ) decided_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)