# 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.working_locations_container import WorkingLocationsContainer
from ..models.utils.cast_models import cast_models
from ..models.team_list_container import TeamListContainer
from ..models.organization_list_container import OrganizationListContainer
from ..models.legal_entity_list_container import LegalEntityListContainer
from ..models.departments_container import DepartmentsContainer
from ..models.agreement_list_container import AgreementListContainer


class OrganizationsService(BaseService):

    @cast_models
    def get_legal_entity_list(self, type_: str = None) -> LegalEntityListContainer:
        """Retrieve a list of legal entities in your account.

        :param type_: Return list of global payroll legal entities if provided, defaults to None
        :type type_: str, optional
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: LegalEntityListContainer
        """

        Validator(str).is_optional().validate(type_)

        serialized_request = (
            Serializer(f"{self.base_url}/legal-entities", self.get_default_headers())
            .add_query("type", type_)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return LegalEntityListContainer._unmap(response)

    @cast_models
    def get_organizations(self) -> OrganizationListContainer:
        """Retrieve the current organization details. Organization is automatically detected from the auth token.

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

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

        response = self.send_request(serialized_request)

        return OrganizationListContainer._unmap(response)

    @cast_models
    def get_teams(self) -> TeamListContainer:
        """Retrieve a list of teams in your organization.

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

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

        response = self.send_request(serialized_request)

        return TeamListContainer._unmap(response)

    @cast_models
    def get_agreements(
        self, contract_id: str = None, limit: str = None, offset: str = None
    ) -> AgreementListContainer:
        """This end-point returns a list of your agreements with Deel.

        :param contract_id: Deel contract id., defaults to None
        :type contract_id: str, optional
        :param limit: Maximum number of records to return., defaults to None
        :type limit: str, optional
        :param offset: Offset/index of record for the next page of records to return., defaults to None
        :type offset: str, optional
        ...
        :raises RequestError: Raised when a request fails, with optional HTTP status code and details.
        ...
        :return: Successful operation.
        :rtype: AgreementListContainer
        """

        Validator(str).is_optional().validate(contract_id)
        Validator(str).is_optional().validate(limit)
        Validator(str).is_optional().validate(offset)

        serialized_request = (
            Serializer(f"{self.base_url}/agreements", self.get_default_headers())
            .add_query("contract_id", contract_id)
            .add_query("limit", limit)
            .add_query("offset", offset)
            .serialize()
            .set_method("GET")
        )

        response = self.send_request(serialized_request)

        return AgreementListContainer._unmap(response)

    @cast_models
    def get_departments(self) -> DepartmentsContainer:
        """Get list of organization departments.

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

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

        response = self.send_request(serialized_request)

        return DepartmentsContainer._unmap(response)

    @cast_models
    def get_working_locations(self) -> WorkingLocationsContainer:
        """Get organization working locations.

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

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

        response = self.send_request(serialized_request)

        return WorkingLocationsContainer._unmap(response)
