defmodule Requests.Payments.Senders.BankPayoutIndividual do
alias Customers.BillingAddress
alias Customers.Identification
@type t :: %__MODULE__{
type: String.t(),
first_name: String.t(),
last_name: String.t(),
dob: String.t(),
address: BillingAddress.t(),
identification: Identification.t(),
reference: String.t()
}
@enforce_keys [:type, :first_name, :last_name, :address]
defstruct [
:type,
:first_name,
:last_name,
:dob,
:address,
:identification,
:reference
]
def build(
%{type: type, first_name: first_name, last_name: last_name, address: address} = params
) do
%{
type: type,
first_name: first_name,
last_name: last_name,
dob: params[:dob],
address: BillingAddress.build(address),
identification: Identification.build(params[:identification]),
reference: params[:reference]
}
end
def build(params) when is_map(params),
do: {:error, "individual sender must have first_name, last_name and address"}
def build(_), do: nil
end