"""Requests to ows-payee.""" from src.connectors.ows_service import OwsService from src.utils.error_handling import BankDetailsException from src.utils.error_handling import OwsServiceException from src.utils.error_handling import TaxDetailsException class OwsPayee(OwsService): """OwsPayee client for fetching requests.""" _service = 'ows-payee' @classmethod def get_tax_details( cls, account_payee_id: int, required_tax_details: list | None = None ) -> dict: """Get tax details for an account payee. Args: account_payee_id (int): ID of the account payee. required_tax_details (list): a list of required tax details. Returns: dict: Tax details. """ if required_tax_details is None: required_tax_details = [] path = f'/account-payee/{account_payee_id}/tax-details' try: # TODO: remove timeout when ows-payee is adjusted to handle traffic spike data = cls.validate_response_type(cls.get(path, timeout=30.0), dict) except OwsServiceException as exception: if exception.status_code == 404: raise TaxDetailsException(exception.message) raise exception for field in required_tax_details: if field not in data or data[field] is None: raise TaxDetailsException(f'{cls._service}: Missing required tax details: {field}') return data @classmethod def get_bank_details( cls, account_payee_id: int, required_tax_details: list | None = None ) -> dict: """Get bank details for an account payee. Args: account_payee_id (int): ID of the account payee. required_tax_details (list): a list of required bank details. Returns: dict: Bank details. """ if required_tax_details is None: required_tax_details = [] path = f'/account-payee/{account_payee_id}/bank-details' try: data = cls.validate_response_type(cls.get(path), dict) except OwsServiceException as exception: if exception.status_code == 404: raise BankDetailsException(exception.message) raise exception for field in required_tax_details: if field not in data or data[field] is None: raise BankDetailsException( f'{cls._service}: Missing required bank details: {field}' ) return data