from __future__ import annotations

from app.domain.mappers import to_sdk_config
from app.repositories.directus.sdk_configs import SdkConfigRepository
from app.schemas.admin import SdkConfigRead, sdk_config_to_read_model


class SdkConfigService:
    """Application service for SDK config management."""

    def __init__(self, repository: SdkConfigRepository | None = None) -> None:
        self.repository = repository or SdkConfigRepository()

    async def list_sdk_configs(self, access_token: str | None = None) -> list[SdkConfigRead]:
        items = await self.repository.list(access_token=access_token)
        return [sdk_config_to_read_model(to_sdk_config(item)) for item in items]

    async def get_sdk_config(
        self,
        sdk_config_id: str,
        access_token: str | None = None,
    ) -> SdkConfigRead | None:
        item = await self.repository.get(sdk_config_id, access_token=access_token)
        if not item:
            return None
        return sdk_config_to_read_model(to_sdk_config(item))
