"""Exception types raised by the parser.

These are reserved for unrecoverable, file-level failures (bad envelope, no
ISA segment, malformed delimiters). Per-claim validation issues are not
exceptions — they are accumulated into ``ValidationReport``.
"""

from __future__ import annotations


class CycloneParseError(Exception):
    """Raised when the file itself cannot be parsed (bad envelope, etc.)."""

    def __init__(self, message: str, *, segment_index: int | None = None) -> None:
        self.segment_index = segment_index
        suffix = f" (segment {segment_index})" if segment_index is not None else ""
        super().__init__(f"{message}{suffix}")


class CycloneValidationError(Exception):
    """Raised by the CLI for envelope-level validation failures (no claims found)."""

    def __init__(self, message: str, *, rule_id: str | None = None, claim_id: str | None = None) -> None:
        self.rule_id = rule_id
        self.claim_id = claim_id
        prefix = f"[{rule_id}] " if rule_id else ""
        claim = f" (claim {claim_id})" if claim_id else ""
        super().__init__(f"{prefix}{message}{claim}")
