"""Demo 5: complete command-line interface."""

import argparse
import contextlib
import logging
import re
import sys
from dataclasses import dataclass
from typing import TextIO


@dataclass(frozen=True)
class WordCount:
    word: str
    count: int


def count_words(source: TextIO, fold: bool) -> dict[str, int]:
    # TODO: Copy and adapt the implementation from demo-v4.py.
    raise NotImplementedError


def top_n(counts: dict[str, int], n: int) -> list[WordCount]:
    # TODO: Copy the implementation from demo-v4.py.
    raise NotImplementedError


def run(args: list[str], stdin: TextIO, stdout: TextIO, stderr: TextIO) -> int:
    """Run the CLI and return 0, 1, or 2."""
    # TODO: Parse -n, --fold/--no-fold, -v, and file arguments.
    # TODO: Read stdin or merge counts from files.
    # TODO: Write results to stdout and errors/logs to stderr.
    raise NotImplementedError


if __name__ == "__main__":
    sys.exit(run(sys.argv[1:], sys.stdin, sys.stdout, sys.stderr))
