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

import logging
import uuid

from django.core.exceptions import PermissionDenied
from django.http import Http404

from hotpocket_soa.dto.accounts import AccessTokenOut
from hotpocket_soa.services import AccessTokensService

LOGGER = logging.getLogger(__name__)


class UIAccessTokensService:
    def __init__(self):
        self.access_tokens_service = AccessTokensService()

    def get_or_404(self,
                   *,
                   account_uuid: uuid.UUID,
                   pk: uuid.UUID,
                   ) -> AccessTokenOut:
        try:
            return AccessTokensService().get(
                account_uuid=account_uuid,
                pk=pk,
            )
        except AccessTokensService.NotFound as exception:
            LOGGER.error(
                'Access Token not found: account_uuid=`%s` pk=`%s`',
                account_uuid,
                pk,
                exc_info=exception,
            )
            raise Http404()
        except AccessTokensService.AccessDenied as exception:
            LOGGER.error(
                'Access Token access denied: account_uuid=`%s` pk=`%s`',
                account_uuid,
                pk,
                exc_info=exception,
            )
            raise PermissionDenied()
