"""Pydantic models for the muse bridge mirror registry API (Phase 7).""" from datetime import datetime from pydantic import Field, field_validator from musehub.models.base import CamelModel _VALID_DIRECTIONS = {"export", "import", "bidirectional"} class CreateMirrorRequest(CamelModel): """Request body for POST /repos/{repo_id}/mirrors.""" git_remote_url: str = Field(..., min_length=1, description="URL of the remote Git repository") git_branch: str = Field("muse-mirror", min_length=1, description="Branch name on the Git remote") direction: str = Field(..., description="Sync direction: 'export', 'import', or 'bidirectional'") auto_export: bool = Field(False, description="Automatically export on every Muse push") @field_validator("direction") @classmethod def _validate_direction(cls, v: str) -> str: if v not in _VALID_DIRECTIONS: raise ValueError( f"direction must be one of {sorted(_VALID_DIRECTIONS)}, got {v!r}" ) return v @field_validator("git_remote_url") @classmethod def _validate_url(cls, v: str) -> str: if not v.strip(): raise ValueError("git_remote_url must not be empty or whitespace") return v.strip() class MirrorResponse(CamelModel): """Wire model for a single bridge mirror entry.""" id: str repo_id: str git_remote_url: str git_branch: str direction: str last_export_muse_commit_id: str | None last_export_git_sha: str | None last_export_at: datetime | None last_import_git_sha: str | None last_import_muse_commit_id: str | None last_import_at: datetime | None auto_export: bool created_by: str created_at: datetime class MirrorListResponse(CamelModel): """Wire model for GET /repos/{repo_id}/mirrors.""" mirrors: list[MirrorResponse] total: int