"""Tenant schemas for API validation.""" import uuid from datetime import datetime from typing import TYPE_CHECKING from pydantic import BaseModel, ConfigDict, Field if TYPE_CHECKING: from app.models.tenant import Tenant class TenantCreate(BaseModel): """Schema for creating a new tenant.""" name: str = Field(..., min_length=1, max_length=255) domain: str | None = Field(None, max_length=255) class TenantResponse(BaseModel): """Schema for tenant response.""" model_config = ConfigDict(from_attributes=True) id: uuid.UUID name: str domain: str | None has_dashboard_token: bool = Field( default=False, description="Whether a dashboard token has been configured", ) created_at: datetime updated_at: datetime @classmethod def from_orm_with_token_check(cls, tenant: "Tenant") -> "TenantResponse": """Create response with dashboard token check.""" return cls( id=tenant.id, name=tenant.name, domain=tenant.domain, has_dashboard_token=tenant.dashboard_token_hash is not None, created_at=tenant.created_at, updated_at=tenant.updated_at, )