"""``askcli ask "<prompt>" [--model NAME] [--config PATH] [--json]``."""

import argparse
import json  # noqa: F401
import logging
import uuid  # noqa: F401
from collections.abc import Sequence
from dataclasses import replace  # noqa: F401
from pathlib import Path  # noqa: F401

from askcli import backend  # noqa: F401  — call it as backend.complete(...), so tests can patch it
from askcli.config import DEFAULTS, Config, load_config  # noqa: F401
from askcli.logjson import configure_logging, request_scope  # noqa: F401

log = logging.getLogger("askcli.cli")


def build_parser() -> argparse.ArgumentParser:
    """One sub-command, ``ask``: a positional ``prompt``; ``--model NAME`` (beats every config
    layer); ``--config PATH`` (default ``askcli.toml`` in the working directory); ``--json``."""
    ...


def ask(prompt: str, cfg: Config) -> str:
    """Serve one request inside ``request_scope(<a fresh id>)``: log exactly two lines on
    ``log`` — ``request start: 'the prompt'`` before ``backend.complete(prompt,
    cfg.model_name)`` and ``request done: <n> answer chars`` after it — and return the answer.
    (The backend logs the third line, ``model call: …``, itself.)"""
    ...


def main(argv: Sequence[str] | None = None) -> int:
    """Parse ``argv``; load the config (``load_config(DEFAULTS, args.config)``) and apply
    ``--model`` on top; ``configure_logging``; ``ask``; print the answer — or, with ``--json``,
    ``{"model": ..., "answer": ...}`` as one JSON line — on stdout. Return 0.

    Bad arguments return 2: argparse prints the usage line and raises ``SystemExit(2)`` —
    catch it and return its code.
    """
    ...
