"""Shared Pydantic base models: ServiceInfo, ServiceType, Error."""

from __future__ import annotations

from typing import Any

from pydantic import BaseModel, ConfigDict


class GA4GHBase(BaseModel):
    """Base model for all GA4GH types with common configuration."""

    model_config = ConfigDict(
        populate_by_name=True,
        str_strip_whitespace=True,
        extra="allow",
    )


class ServiceType(GA4GHBase):
    """GA4GH Service Type descriptor."""

    group: str
    artifact: str
    version: str


class Organization(GA4GHBase):
    """Organization that hosts a GA4GH service."""

    name: str
    url: str


class ServiceInfo(GA4GHBase):
    """GA4GH Service Info response model (v1.0.0)."""

    id: str
    name: str
    type: ServiceType
    description: str | None = None
    organization: Organization | None = None
    contact_url: str | None = None
    documentation_url: str | None = None
    created_at: str | None = None
    updated_at: str | None = None
    environment: str | None = None
    version: str | None = None


class GA4GHError(GA4GHBase):
    """GA4GH standard error response."""

    status_code: int
    message: str
    error_code: str | None = None


class AccessMethod(GA4GHBase):
    """DRS access method."""

    type: str
    access_url: dict[str, Any] | None = None
    access_id: str | None = None
    region: str | None = None
