from __future__ import annotations

from datetime import date

from src.errors import UserError


def parse_date_range(from_date: str, to_date: str) -> tuple[date, date]:
    try:
        from_d = date.fromisoformat(from_date)
        to_d = date.fromisoformat(to_date)
    except ValueError as exc:
        raise UserError("Dates must be in YYYY-MM-DD format.") from exc
    if from_d > to_d:
        raise UserError("--from must be <= --to.")
    return (from_d, to_d)
