lib/customers/phone.ex

defmodule Customers.Phone do
    @moduledoc false
  @derive Jason.Encoder

  @type t() :: %__MODULE__{
          country_code: String.t(),
          number: String.t()
        }

  defstruct [
    :country_code,
    :number
  ]

  @spec build(%{:country_code => String.t(), :number => String.t()}) ::
          Customers.Phone.t()

  def build(%{country_code: country_code, number: number}) do
    %__MODULE__{
      country_code: country_code,
      number: number
    }
  end

  def build(%{"country_code" => country_code, "number" => number}) do
    %{
      country_code: country_code,
      number: number
    }
  end

  def build(_), do: nil
end