"""Schemas for Forgejo issue metrics."""

from __future__ import annotations

from datetime import datetime
from uuid import UUID

from sqlmodel import SQLModel


class RepositorySyncHealth(SQLModel):
    """Sync health for a single tracked repository."""

    repository_id: UUID
    owner: str
    repo: str
    display_name: str | None = None
    last_sync_at: datetime | None = None
    last_sync_error: str | None = None
    has_error: bool = False


class ForgejoIssueMetrics(SQLModel):
    """Aggregate Forgejo issue tracking metrics."""

    open_issues: int
    closed_issues: int
    recently_closed: int  # closed in last 7 days
    stale_open: int  # open > 14 days with no update
    total_issues: int
    repositories_health: list[RepositorySyncHealth] = []