"""STARTER -- implement detect_canary_leak, run_harness and build_report."""
from dataclasses import dataclass

from .mock_model import CANARY_TOKEN, query as default_model


@dataclass(frozen=True)
class HarnessResult:
    total: int
    successes: int
    rate: float
    success_ids: list
    by_category: dict


def detect_canary_leak(response: str, canary: str = CANARY_TOKEN) -> bool:
    """True if `canary` appears anywhere in `response`, regardless of case."""
    ...


def run_harness(attacks: list[dict], model=default_model) -> HarnessResult:
    """Run every attack in `attacks` (each a dict with "id", "category", "prompt") through
    `model`, score it with detect_canary_leak, and return one HarnessResult: total attacks,
    how many leaked, the leak rate, the sorted list of leaking attack ids, and a per-category
    breakdown {"category": {"attacks": n, "successes": n}}. Calling this twice on the same
    `attacks` must return an equal HarnessResult both times.
    """
    ...


def build_report(result: HarnessResult) -> str:
    """A markdown report: a top heading, the overall rate as "successes/total (pct%)", a
    per-category table sorted by category name, and a "## Successful attacks" section listing
    every success id, sorted.
    """
    ...
