"""Requests to ows-payee.""" from http import HTTPStatus from src.exceptions import OwsPayeeException from src.models import ( MovePayoneerProgramData, MovePayoneerProgramResponse, PayoneerStatusData, PayoneerStatusResponse, ) from src.requests import delete, get, post SERVICE = 'ows-payee' def get_payoneer_payee_status( account_payee_id: int, program_id: int ) -> PayoneerStatusData: """Get Payoneer payee status data.""" path = f'/account-payee/{account_payee_id}/program/{program_id}/payoneer-status/' response = get(SERVICE, path) if response.status_code != 200: raise OwsPayeeException(f'ERROR in GET {path}') return PayoneerStatusResponse.model_validate(response.json()).result def move_payoneer_program( account_payee_id: int, existing_payoneer_program_id: int, new_payoneer_program_id: int, ) -> MovePayoneerProgramData: """Move Payoneer program.""" path = f'/account-payee/{account_payee_id}/move-payoneer-program/' response = post( SERVICE, path, { 'existing_payoneer_program_id': existing_payoneer_program_id, 'new_payoneer_program_id': new_payoneer_program_id, }, ) if response.status_code != HTTPStatus.OK: raise OwsPayeeException( f'Failed to move payee payoneer program: {response.text}' ) return MovePayoneerProgramResponse.model_validate(response.json()).result def release_payee_payoneer_program( account_payee_id: int, payoneer_program_id: int ) -> None: """Release payee from payoneer program. This function removes the association between a payee and their previous Payoneer program after a successful program move. Args: account_payee_id: The ID of the account payee to release. payoneer_program_id: The ID of the Payoneer program to release from. Raises: OwsPayeeException: If the API request fails. """ path = f'/account-payee/{account_payee_id}/payoneer-account' response = delete(SERVICE, path, body={'payoneer_program_id': payoneer_program_id}) if response.status_code != HTTPStatus.OK: raise OwsPayeeException( f'Failed to release payee from payoneer program: {response.text}' ) def reset_banking_states(account_payee_id: int) -> None: """ Reset banking states. /account-payee//reset-banking-states/ """ path = f'/account-payee/{account_payee_id}/reset-banking-states/' response = post(SERVICE, path, {}) if response.status_code != HTTPStatus.OK: raise OwsPayeeException(f'Failed to reset banking states: {response.text}')