# This file was generated by liblab | https://liblab.com/

from .utils.validator import Validator
from .utils.base_service import BaseService
from ..net.transport.serializer import Serializer
from ..models.utils.cast_models import cast_models
from ..models.public_token_created_container import PublicTokenCreatedContainer
from ..models.create_public_token_container import CreatePublicTokenContainer


class TokenService(BaseService):

    @cast_models
    def create_public_token(
        self, request_body: CreatePublicTokenContainer
    ) -> PublicTokenCreatedContainer:
        """Create a public token to use with embedded Deel SDK components.

        :param request_body: The request body.
        :type request_body: CreatePublicTokenContainer
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: PublicTokenCreatedContainer
        """

        Validator(CreatePublicTokenContainer).validate(request_body)

        serialized_request = (
            Serializer(f"{self.base_url}/public-tokens", self.get_default_headers())
            .serialize()
            .set_method("POST")
            .set_body(request_body)
        )

        response = self.send_request(serialized_request)

        return PublicTokenCreatedContainer._unmap(response)
