"""Looker-specific exceptions and validation helpers."""

from __future__ import annotations

from typing import Iterable


class LookerError(Exception):
    """Base exception for Looker integration errors."""


class LookerApiError(LookerError):
    """Raised when Looker API calls fail."""


class LookerSpecError(LookerError):
    """Raised when dashboard/look spec validation fails."""


class LookerAmbiguousMatchError(LookerError):
    """Raised when upsert matching resolves to multiple resources."""


def summarize_pydantic_errors(errors: Iterable[dict]) -> str:
    """Convert pydantic error payload into a short readable summary."""
    parts: list[str] = []
    for err in errors:
        loc = ".".join(str(item) for item in err.get("loc") or [])
        msg = str(err.get("msg") or "invalid value")
        if loc:
            parts.append(f"{loc}: {msg}")
        else:
            parts.append(msg)
    return "; ".join(parts) if parts else "Invalid spec"
