import uuid from datetime import datetime from sqlalchemy import String, Integer, DateTime, func from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy.dialects.postgresql import UUID from app.db import Base class Workspace(Base): __tablename__ = "workspaces" id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) name: Mapped[str] = mapped_column(String(255), nullable=False) slug: Mapped[str] = mapped_column(String(100), unique=True, nullable=False) plan_tier: Mapped[str] = mapped_column(String(50), default="free") # free|pro|business monthly_quota: Mapped[int] = mapped_column(Integer, default=5) stripe_customer_id: Mapped[str | None] = mapped_column(String(255), nullable=True) stripe_subscription_id: Mapped[str | None] = mapped_column(String(255), nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) class WorkspaceMember(Base): __tablename__ = "workspace_members" workspace_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True) user_id: Mapped[str] = mapped_column(String(255), primary_key=True) role: Mapped[str] = mapped_column(String(50), default="member") # owner|admin|member created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now()) class UsageEvent(Base): __tablename__ = "usage_events" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) workspace_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), nullable=False) event_type: Mapped[str] = mapped_column(String(100), nullable=False) # pdf_checked|remediated|api_call job_id: Mapped[uuid.UUID | None] = mapped_column(UUID(as_uuid=True), nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())