from datetime import datetime
from typing import Any

from pydantic import BaseModel, Field


class OpsRunProjectionItem(BaseModel):
    id: str
    definition: str | None = None
    target_repo: str | None = None
    state: str
    lease: dict[str, Any] | None = None
    updated_at: datetime | None = None
    last_error: str | None = None


class OpsRunProjection(BaseModel):
    available: bool = False
    stale: bool = False
    source: str = "activity-core"
    generated_at: datetime
    open: int = 0
    claimed: int = 0
    failed_24h: int = 0
    stuck_open_or_claimed: int = 0
    items: list[OpsRunProjectionItem] = Field(default_factory=list)
    error: str | None = None
