defmodule Rad2.Auth.Company do @moduledoc """ Represents a Company Companies represents the costumer of RAD² services, and each user in our platform can ben related with many companies """ @type t :: %__MODULE__{ id: String.t(), name: String.t(), document: String.t() } defstruct [:id, :name, :document] def new(%{} = map) do %__MODULE__{} |> put_id(map) |> put_name(map) |> put_document(map) end defp put_id(struct, %{"id" => id}), do: Map.put(struct, :id, id) defp put_id(_, _), do: {:error, :missing_fields} defp put_name(struct, %{"name" => name}), do: Map.put(struct, :name, name) defp put_name(_, _), do: {:error, :missing_fields} defp put_document(struct, %{"document" => document}), do: Map.put(struct, :document, document) defp put_document(_, _), do: {:error, :missing_fields} end