"""Pydantic schemas for auth endpoints.""" from pydantic import BaseModel, EmailStr, Field, field_validator class RegisterRequest(BaseModel): email: EmailStr password: str = Field(min_length=8) display_name: str = Field(min_length=1, max_length=100) # Optional: lets a partner register straight from an invite link instead # of first creating a throwaway solo workspace. When present, `register` # joins the inviting workspace directly (claiming a placeholder member # if one exists) instead of creating a new one. invite_token: str | None = None @field_validator("email") @classmethod def normalize_email(cls, v: str) -> str: """Lowercase at the API boundary — storage/lookup is case-sensitive (`WHERE email = ?`), so Foo@x.se and foo@x.se must resolve to one account rather than silently becoming two.""" return v.lower() class LoginRequest(BaseModel): email: EmailStr password: str @field_validator("email") @classmethod def normalize_email(cls, v: str) -> str: """Lowercase at the API boundary — see `RegisterRequest.normalize_email`.""" return v.lower() class TokenResponse(BaseModel): access_token: str token_type: str = "bearer" expires_in: int # seconds until expiry class UserMeResponse(BaseModel): id: str email: str display_name: str workspace_id: str | None