"""Adapter for transforming Backup API responses to SDK models.

This adapter provides minimal transformation from raw API responses to typed SDK models.
All transformations are documented to explain why they're needed.
"""

from typing import Any

from pinecone.models.backups import BackupModel


class BackupsAdapter:
    """Adapter for Backup API responses.

    This class transforms raw API responses into typed SDK models. Each transformation
    is kept minimal and documented.
    """

    @staticmethod
    def to_backup_model(data: dict[str, Any]) -> BackupModel:
        """Transform backup API response to BackupModel.

        Args:
            data: Raw API response dictionary

        Returns:
            Typed BackupModel

        Transformations:
            - Direct field mapping from API response to model
            - All optional fields handled with .get() for safety
        """
        return BackupModel(
            backup_id=data["backup_id"],
            source_index_name=data["source_index_name"],
            source_index_id=data["source_index_id"],
            status=data["status"],
            cloud=data["cloud"],
            region=data["region"],
            created_at=data["created_at"],
            name=data.get("name"),
            description=data.get("description"),
            dimension=data.get("dimension"),
            metric=data.get("metric"),
            record_count=data.get("record_count"),
            namespace_count=data.get("namespace_count"),
            size_bytes=data.get("size_bytes"),
            tags=data.get("tags"),
            schema=data.get("schema"),
        )

    @staticmethod
    def to_backup_list(data: dict[str, Any]) -> list[BackupModel]:
        """Transform paginated list response to list of BackupModel.

        Args:
            data: Raw API response dictionary with 'data' field containing list

        Returns:
            List of typed BackupModel objects

        Transformations:
            - Iterates through 'data' array from API response
            - Transforms each item using to_backup_model()
        """
        return [BackupsAdapter.to_backup_model(item) for item in data["data"]]
