# `Trogon.Commanded.Enum`
[🔗](https://github.com/straw-hat-team/beam-monorepo/blob/trogon_commanded@v1.0.1/apps/trogon_commanded/lib/trogon/commanded/enum.ex#L1)

Defines an Enum type module.

# `__using__`
*macro* 

Converts the module into a struct with an `:value` enum field.

## Using

- `Ecto.Schema`
- `Ecto.Type`

## Derives

- `Jason.Encoder`

## Usage

    defmodule BankAccountType do
      use Trogon.Commanded.Enum, values: [:business, :personal]
    end

    {:ok, type} = BankAccountType.new(:business)

You can use it in your `Ecto.Schema` like this:

    defmodule BankAccount do
      use Ecto.Schema

      embedded_schema do
        field :type, BankAccountType
      end
    end

## Proto-driven Enum

You can derive values from a protobuf enum module instead of a hardcoded list:

    defmodule ObjectTypeEnum do
      use Trogon.Commanded.Enum,
        proto: Acme.Type.V1.ObjectType
    end

The enum values are derived at compile time, sorted by their proto field number.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
