defmodule Requests.Payments.Destinations.Id do
@moduledoc false
alias Requests.Payments.Destinations.Holders.{
CorporateAccount,
GovernmentAccount,
IndividualAccount
}
@type t :: %__MODULE__{
account_holder: map(),
id: String.t(),
type: String.t()
}
@enforce_keys [:account_holder, :id, :type]
defstruct [
:account_holder,
:id,
:type
]
def build(params) when is_map(params) do
%{
account_holder: build_account_holder(params[:account_holder]),
token: params[:token],
type: params[:type]
}
end
def build(_), do: nil
defp build_account_holder(%{type: "individual"} = params),
do: IndividualAccount.build(params)
defp build_account_holder(%{type: "corporate"} = params),
do: CorporateAccount.build(params)
defp build_account_holder(%{type: "government"} = params),
do: GovernmentAccount.build(params)
defp build_account_holder(_), do: nil
end