from typing import Any

from pydantic import BaseModel, ConfigDict, Field


class SealedProjectionRepairSubmit(BaseModel):
    plan: dict[str, Any]
    repo_slug: str = Field(pattern=r"^[a-z0-9][a-z0-9-]{0,99}$")
    unit: dict[str, Any]
    expected_plan_sha256: str = Field(pattern=r"^[0-9a-f]{64}$")
    source_revision: str = Field(pattern=r"^[0-9a-f]{40}$")
    source_fingerprint: str = Field(pattern=r"^[0-9a-f]{64}$")
    source_clean: bool
    source_synchronized: bool
    primary_confirmed: bool
    projection_identity: str = Field(min_length=1, max_length=200)


class SealedProjectionRepairReceiptRead(BaseModel):
    model_config = ConfigDict(populate_by_name=True)

    schema_version: str = Field(alias="schema")
    outcome: str
    repo_slug: str
    repository_id: str
    workplan_record_id: str
    workplan_old_id: str
    task_records: list[tuple[str, str]]
    plan_sha256: str
    source_revision: str
    source_fingerprint: str
    projection_identity: str
    observed_at: str


class IdentifierMigrationApplySubmit(BaseModel):
    plan: dict[str, Any]
    expected_plan_sha256: str = Field(pattern=r"^[0-9a-f]{64}$")
    primary_confirmed: bool
