# 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.org_structure_to_update_container import OrgStructureToUpdateContainer
from ..models.org_structure_to_create_container import OrgStructureToCreateContainer
from ..models.get_org_structure_container import GetOrgStructureContainer
from ..models.get_all_org_structures_container import GetAllOrgStructuresContainer


class OrganizationStructureService(BaseService):

    @cast_models
    def get_all_org_structures(self) -> GetAllOrgStructuresContainer:
        """Fetch all Org Structures from the Organization.

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

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

        response = self.send_request(serialized_request)

        return GetAllOrgStructuresContainer._unmap(response)

    @cast_models
    def create_org_structure(
        self, request_body: OrgStructureToCreateContainer
    ) -> GetAllOrgStructuresContainer:
        """Create a new HRIS Organization Structure.

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

        Validator(OrgStructureToCreateContainer).validate(request_body)

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

        response = self.send_request(serialized_request)

        return GetAllOrgStructuresContainer._unmap(response)

    @cast_models
    def get_org_structure(self, hris_org_str_id: str) -> GetOrgStructureContainer:
        """Fetch an Org Structure from the Organization.

        :param hris_org_str_id: HRIS Organization Structure ID.
        :type hris_org_str_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: GetOrgStructureContainer
        """

        Validator(str).validate(hris_org_str_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/hris/organization_structures/{{hrisOrgStr_id}}",
                self.get_default_headers(),
            )
            .add_path("hrisOrgStr_id", hris_org_str_id)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return GetOrgStructureContainer._unmap(response)

    @cast_models
    def update_org_structure(
        self, request_body: OrgStructureToUpdateContainer, hris_org_str_id: str
    ) -> any:
        """Update an existing Organization structure.

        :param request_body: The request body.
        :type request_body: OrgStructureToUpdateContainer
        :param hris_org_str_id: HRIS Organization Structure ID.
        :type hris_org_str_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: any
        """

        Validator(OrgStructureToUpdateContainer).validate(request_body)
        Validator(str).validate(hris_org_str_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/hris/organization_structures/{{hrisOrgStr_id}}",
                self.get_default_headers(),
            )
            .add_path("hrisOrgStr_id", hris_org_str_id)
            .serialize()
            .set_method("PATCH")
            .set_body(request_body)
        )

        response = self.send_request(serialized_request)

        return response

    @cast_models
    def delete_org_structure(self, hris_org_str_id: str) -> any:
        """Delete an Org Structure from the Organization.

        :param hris_org_str_id: HRIS Organization Structure ID.
        :type hris_org_str_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successfully deleted.
        :rtype: any
        """

        Validator(str).validate(hris_org_str_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/hris/organization_structures/{{hrisOrgStr_id}}",
                self.get_default_headers(),
            )
            .add_path("hrisOrgStr_id", hris_org_str_id)
            .serialize()
            .set_method("DELETE")
        )

        response = self.send_request(serialized_request)

        return response

    @cast_models
    def get_external_org_structure(self, external_id: str) -> GetOrgStructureContainer:
        """Fetch an Org Structure from the Organization.

        :param external_id: External ID.
        :type external_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: GetOrgStructureContainer
        """

        Validator(str).validate(external_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/hris/organization_structures/external/{{external_id}}",
                self.get_default_headers(),
            )
            .add_path("external_id", external_id)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return GetOrgStructureContainer._unmap(response)

    @cast_models
    def update_external_org_structure(
        self, request_body: OrgStructureToUpdateContainer, external_id: str
    ) -> any:
        """Update an existing Organization structure.

        :param request_body: The request body.
        :type request_body: OrgStructureToUpdateContainer
        :param external_id: External ID.
        :type external_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: any
        """

        Validator(OrgStructureToUpdateContainer).validate(request_body)
        Validator(str).validate(external_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/hris/organization_structures/external/{{external_id}}",
                self.get_default_headers(),
            )
            .add_path("external_id", external_id)
            .serialize()
            .set_method("PATCH")
            .set_body(request_body)
        )

        response = self.send_request(serialized_request)

        return response

    @cast_models
    def delete_external_org_structure(self, external_id: str) -> any:
        """Delete an Org Structure from the Organization.

        :param external_id: External ID.
        :type external_id: str
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successfully deleted.
        :rtype: any
        """

        Validator(str).validate(external_id)

        serialized_request = (
            Serializer(
                f"{self.base_url}/hris/organization_structures/external/{{external_id}}",
                self.get_default_headers(),
            )
            .add_path("external_id", external_id)
            .serialize()
            .set_method("DELETE")
        )

        response = self.send_request(serialized_request)

        return response
