# 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.updated_role_container import UpdatedRoleContainer
from ..models.role_to_update_container import RoleToUpdateContainer
from ..models.role_to_create_container import RoleToCreateContainer
from ..models.get_roles_container import GetRolesContainer
from ..models.created_role_container import CreatedRoleContainer


class HrisOrganizationsService(BaseService):

    @cast_models
    def get_organization_roles(self) -> GetRolesContainer:
        """Get the roles of the current organization.

        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: GetRolesContainer
        """

        serialized_request = (
            Serializer(f"{self.base_url}/roles", self.get_default_headers())
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return GetRolesContainer._unmap(response)

    @cast_models
    def create_organization_role(
        self, request_body: RoleToCreateContainer
    ) -> CreatedRoleContainer:
        """Create organization custom role.

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

        Validator(RoleToCreateContainer).validate(request_body)

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

        response = self.send_request(serialized_request)

        return CreatedRoleContainer._unmap(response)

    @cast_models
    def update_organization_role(
        self, request_body: RoleToUpdateContainer, role_id: str
    ) -> UpdatedRoleContainer:
        """Update organization custom role.

        :param request_body: The request body.
        :type request_body: RoleToUpdateContainer
        :param role_id: ID of the role.
        :type role_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: UpdatedRoleContainer
        """

        Validator(RoleToUpdateContainer).validate(request_body)
        Validator(str).validate(role_id)

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

        response = self.send_request(serialized_request)

        return UpdatedRoleContainer._unmap(response)
