"""Types and options for GitHub CI error retrieval."""

from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path
from typing import TypedDict


class CiAnnotation(TypedDict):
    path: str
    start_line: int | None
    end_line: int | None
    title: str | None
    message: str


class CiFailure(TypedDict):
    check_run_id: int
    name: str
    conclusion: str | None
    details_url: str | None
    annotations: list[CiAnnotation]
    log_tail: str | None
    log_tail_path: str | None
    error_excerpt: str | None


class CiErrorsResponse(TypedDict):
    ok: bool
    repo: str
    pr_number: int
    head_sha: str
    failures: list[CiFailure]
    message: str | None


@dataclass(frozen=True)
class CiErrorsOptions:
    max_failed_checks: int = 6
    max_annotations_per_check: int = 30
    include_log_tails: bool = False
    include_log_tails_if_generic: bool = True
    log_tail_max_bytes: int = 65536
    save_log_files: bool = True
    log_dir: Path | None = None
