"""Required explicit CLI values for a one-use r71b maintenance preseal."""

from __future__ import annotations

from collections.abc import Sequence
from dataclasses import dataclass
from pathlib import Path

from scripts.nutricoach_v150_r71b_preparation import (
    MaintenanceWindow,
    parse_maintenance_window,
)


@dataclass(frozen=True, slots=True)
class R71bPresealArguments:
    """All caller-supplied paths plus the mandatory bounded KST maintenance window."""

    candidate_root: Path
    hermes_wheel: Path
    profile_wheel: Path
    window: MaintenanceWindow


def parse_preseal_arguments(arguments: Sequence[str]) -> R71bPresealArguments:
    """Parse exactly three paths and three explicit KST window flags."""
    values = tuple(arguments)
    if len(values) != 9:
        raise ValueError(" ".join((
            "usage: preparer CANDIDATE_ROOT HERMES_WHEEL PROFILE_WHEEL",
            "--maintenance-kst-day DAY --maintenance-not-before INSTANT",
            "--maintenance-expires-at INSTANT",
        )))
    candidate_root, hermes_wheel, profile_wheel = values[:3]
    flags = values[3:]
    expected = (
        "--maintenance-kst-day",
        "--maintenance-not-before",
        "--maintenance-expires-at",
    )
    if tuple(flags[::2]) != expected or any(not value for value in flags[1::2]):
        raise ValueError("maintenance_window_arguments")
    return R71bPresealArguments(
        Path(candidate_root),
        Path(hermes_wheel),
        Path(profile_wheel),
        parse_maintenance_window(flags[1], flags[3], flags[5]),
    )
