"""Account payee marshmallow schema.""" from datetime import datetime from typing import TypedDict from abacus_common_logic.marshalling.custom_fields import ma from marshmallow import pre_load, validate class BaseAccountPayeeSchema(ma.Schema): """Account payee schema.""" payoneer_program_id = ma.NonNegativeInteger() payoneer_payee_id = ma.NonNegativeInteger(allow_none=True) payoneer_payee_name = ma.String(allow_none=True) payoneer_iframe_url = ma.String() payoneer_iframe_url_date = ma.FormattedDate() payoneer_session_id = ma.String() sap_vendor_id = ma.NonNegativeInteger(allow_none=True) reference_payment_type_id = ma.NonNegativeInteger(allow_none=True) payment_description = ma.String( allow_none=True, validate=[validate.Length(max=250)] ) @pre_load def strip_description(self, data, **kwargs): """Strip whitespace from description field.""" if 'payment_description' in data: if data['payment_description'] is not None: data['payment_description'] = data['payment_description'].strip() else: data['payment_description'] = '' return data class AccountPayeeDetailSchema(BaseAccountPayeeSchema): """account_payee GET body.""" account_id = ma.IntegerId(required=True) account_payee_id = ma.IntegerId(required=True) last_modified = ma.FormattedDate(required=True) class AccountPayeePostSchema(BaseAccountPayeeSchema): """account_payment_term POST body.""" account_id = ma.IntegerId(required=True) class AccountPayeePutSchema(BaseAccountPayeeSchema): """account_payment_term PUT body.""" payoneer_program_id = ma.NonNegativeInteger(allow_none=True) class AccountPayeeDetail(TypedDict): """TypedDict that mirrors the serialized output from AccountPayeeDetailSchema.""" account_id: int account_payee_id: str last_modified: datetime