# 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.eor_payslips_list_container import EorPayslipsListContainer
from ..models.eor_payslip_download_url_container import EorPayslipDownloadUrlContainer
from ..models.eor_employee_cost_calculation_response_container import (
    EorEmployeeCostCalculationResponseContainer,
)
from ..models.eor_employee_cost_calculation_request_body_container import (
    EorEmployeeCostCalculationRequestBodyContainer,
)
from ..models.eor_country_validations_container import EorCountryValidationsContainer
from ..models.eor_contract_to_create_container import EorContractToCreateContainer
from ..models.eor_contract_created_container import EorContractCreatedContainer
from ..models.eor_contract_benefits_container import EorContractBenefitsContainer


class EorService(BaseService):

    @cast_models
    def get_eor_country_validations(
        self, country_code: str
    ) -> EorCountryValidationsContainer:
        """Retrieve the hiring guide data for a country. This data can be used to create Employee of Record (EOR) contract quotes.

        :param country_code: Country code.
        :type country_code: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: EorCountryValidationsContainer
        """

        Validator(str).min_length(2).max_length(2).pattern("^[A-Z]{2}$").validate(
            country_code
        )

        serialized_request = (
            Serializer(
                f"{self.base_url}/eor/validations/{{country_code}}",
                self.get_default_headers(),
            )
            .add_path("country_code", country_code)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return EorCountryValidationsContainer._unmap(response)

    @cast_models
    def get_eor_worker_payslips(self, worker_id: str) -> EorPayslipsListContainer:
        """Get of payslips for an employee.

        :param worker_id: Unique identifier for a worker.
        :type worker_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: EorPayslipsListContainer
        """

        Validator(str).validate(worker_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/eor/workers/{{worker_id}}/payslips",
                self.get_default_headers(),
            )
            .add_path("worker_id", worker_id)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return EorPayslipsListContainer._unmap(response)

    @cast_models
    def get_eor_worker_payslip_download_url(
        self, worker_id: str, payslip_id: str
    ) -> EorPayslipDownloadUrlContainer:
        """Get download url for EOR payslip.

        :param worker_id: Unique identifier for a worker.
        :type worker_id: str
        :param payslip_id: Unique identifier for a payslip.
        :type payslip_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: EorPayslipDownloadUrlContainer
        """

        Validator(str).validate(worker_id)
        Validator(str).validate(payslip_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/eor/workers/{{worker_id}}/payslips/{{payslip_id}}/download",
                self.get_default_headers(),
            )
            .add_path("worker_id", worker_id)
            .add_path("payslip_id", payslip_id)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return EorPayslipDownloadUrlContainer._unmap(response)

    @cast_models
    def calculate_eor_employment_cost(
        self, request_body: EorEmployeeCostCalculationRequestBodyContainer = None
    ) -> EorEmployeeCostCalculationResponseContainer:
        """Determine EOR employee costs across the globe.

        :param request_body: The request body., defaults to None
        :type request_body: EorEmployeeCostCalculationRequestBodyContainer, optional
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: EorEmployeeCostCalculationResponseContainer
        """

        Validator(
            EorEmployeeCostCalculationRequestBodyContainer
        ).is_optional().validate(request_body)

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

        response = self.send_request(serialized_request)

        return EorEmployeeCostCalculationResponseContainer._unmap(response)

    @cast_models
    def get_eor_contract_benefits(
        self, contract_id: str
    ) -> EorContractBenefitsContainer:
        """Retrieve EOR contract benefits

        :param contract_id: Deel contract id.
        :type contract_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: EorContractBenefitsContainer
        """

        Validator(str).validate(contract_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/eor/{{contract_id}}/benefits",
                self.get_default_headers(),
            )
            .add_path("contract_id", contract_id)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return EorContractBenefitsContainer._unmap(response)

    @cast_models
    def create_eor_contract(
        self, request_body: EorContractToCreateContainer
    ) -> EorContractCreatedContainer:
        """Create an Employee of Record (EOR) contract quote. The endpoints creates a contract quote request. Deel will process the information and get back with a quote for this contract.

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

        Validator(EorContractToCreateContainer).validate(request_body)

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

        response = self.send_request(serialized_request)

        return EorContractCreatedContainer._unmap(response)
