# -*- coding: utf-8 -*-
from __future__ import annotations

import uuid

from hotpocket_backend.apps.accounts.services import (
    AccountsService as BackendAccountsService,
)
from hotpocket_soa.dto.accounts import AccountOut
from hotpocket_soa.exceptions.backend import NotFound

from .base import ProxyService, SOAError


class AccountsService(ProxyService):
    class AccountsServiceError(SOAError):
        pass

    class NotFound(AccountsServiceError):
        pass

    def __init__(self):
        super().__init__()
        self.backend_accounts_service = BackendAccountsService()

    def get_error_class(self) -> type[SOAError]:
        return self.AccountsServiceError

    def get(self, *, pk: uuid.UUID) -> AccountOut:
        try:
            result = AccountOut.model_validate(
                self.call(
                    self.backend_accounts_service,
                    'get',
                    pk=pk,
                ),
                from_attributes=True,
            )

            return result
        except NotFound as exception:
            raise self.NotFound.from_backend_error(exception)
