# 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.generic_result_updated import GenericResultUpdated
from ..models.generic_result_created import GenericResultCreated
from ..models.candidate_to_patch_container import CandidateToPatchContainer
from ..models.candidate_to_create_container import CandidateToCreateContainer


class CandidatesService(BaseService):

    @cast_models
    def add_candidate(
        self, request_body: CandidateToCreateContainer
    ) -> GenericResultCreated:
        """Add a candidate to Deel.

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

        Validator(CandidateToCreateContainer).validate(request_body)

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

        response = self.send_request(serialized_request)

        return GenericResultCreated._unmap(response)

    @cast_models
    def patch_candidate(
        self, request_body: CandidateToPatchContainer, candidate_id: str
    ) -> GenericResultUpdated:
        """Update an existed candidate.

        :param request_body: The request body.
        :type request_body: CandidateToPatchContainer
        :param candidate_id: Candidate id.
        :type candidate_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: GenericResultUpdated
        """

        Validator(CandidateToPatchContainer).validate(request_body)
        Validator(str).validate(candidate_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/candidates/{{candidate_id}}",
                self.get_default_headers(),
            )
            .add_path("candidate_id", candidate_id)
            .serialize()
            .set_method("PATCH")
            .set_body(request_body)
        )

        response = self.send_request(serialized_request)

        return GenericResultUpdated._unmap(response)
