from __future__ import annotations

from dataclasses import dataclass, field
from pathlib import Path


@dataclass(frozen=True, slots=True)
class Issue:
    code: str
    message: str
    severity: str = "ERROR"
    line: int | None = None
    column: int | None = None
    suggestion: str | None = None

    def location(self) -> str:
        if self.line is None:
            return ""
        if self.column is None:
            return f":{self.line}"
        return f":{self.line}:{self.column}"


@dataclass(frozen=True, slots=True)
class ValidationResult:
    path: Path
    document_type: str
    issues: tuple[Issue, ...] = field(default_factory=tuple)

    @property
    def is_valid(self) -> bool:
        return not any(issue.severity in {"ERROR", "SECURITY"} for issue in self.issues)
