# `ExAcme.RegistrationBuilder`
[🔗](https://github.com/jtdowney/ex_acme/blob/main/lib/ex_acme/registration_builder.ex#L1)

Represents an [ACME Account registration](https://datatracker.ietf.org/doc/html/rfc8555#section-7.3).

Provides functionalities to create and manage account registrations with the ACME server.

### Attributes

  - `contact` - List of contact URIs.
  - `terms_of_service_agreed` - Boolean indicating agreement to terms.
  - `only_return_existing` - Boolean to indicate if only existing accounts should be returned.
  - `external_account_binding` - External account binding information.

# `t`

```elixir
@type t() :: %ExAcme.RegistrationBuilder{
  contact: [String.t()],
  external_account_binding: map() | nil,
  only_return_existing: boolean(),
  terms_of_service_agreed: boolean()
}
```

ACME Account registration object

# `agree_to_terms`

```elixir
@spec agree_to_terms(t()) :: t()
```

Agrees to the terms of service for the registration.

## Parameters

  - `registration` - The current registration struct.

## Returns

  - Updated `ExAcme.RegistrationBuilder` struct.

# `contacts`

```elixir
@spec contacts(t(), [String.t()] | String.t() | [{:email, [String.t()] | String.t()}]) ::
  t()
```

Adds contact URIs to the registration.

## Parameters

  - `registration` - The current registration struct.
  - `contacts` - can be:
    - A list or single contact URI.
    - When used as a keyword argument (i.e., `email: "user@example.com"`),
      provides a convenient way to add email contacts. The function automatically
      prefixes email addresses with "mailto:".

## Returns

  - Updated `ExAcme.RegistrationBuilder` struct.

## Examples

    # Add a single email contact
    iex> registration = ExAcme.RegistrationBuilder.new_registration()
    iex> |> ExAcme.RegistrationBuilder.contacts(email: "admin@example.com")
    iex> registration.contact
    ["mailto:admin@example.com"]

    # Add multiple email contacts
    iex> registration = ExAcme.RegistrationBuilder.new_registration()
    iex> |> ExAcme.RegistrationBuilder.contacts(email: ["admin@example.com", "support@example.com"])
    iex> registration.contact
    ["mailto:admin@example.com", "mailto:support@example.com"]

    # Add a direct URI contact
    iex> registration = ExAcme.RegistrationBuilder.new_registration()
    iex> |> ExAcme.RegistrationBuilder.contacts("mailto:user@example.com")
    iex> registration.contact
    ["mailto:user@example.com"]

# `external_account_binding`

```elixir
@spec external_account_binding(
  t(),
  JOSE.JWK.t(),
  ExAcme.client(),
  String.t(),
  String.t()
) :: t()
```

Configures the external account binding for the registration.

This function sets up an external account binding using the provided key, client,
external account binding key ID, and MAC key.

## Parameters

  - `registration` - The current registration struct.
  - `key` - The `JOSE.JWK` key being registered.
  - `client` - The ExAcme client name or pid.
  - `eab_kid` - The external account binding key ID.
  - `eab_mac_key` - The external account binding MAC key. This must be a valid base64url-encoded
     string.

## Returns

  - Updated `ExAcme.RegistrationBuilder` struct with external account binding.

# `new_registration`

```elixir
@spec new_registration() :: t()
```

Creates a new account registration struct with default values.

## Returns

  - `ExAcme.RegistrationBuilder` struct.

# `to_map`

```elixir
@spec to_map(t()) :: map()
```

Converts the registration struct to a map.

This function transforms the RegistrationBuilder struct into a map format,
removes nil values, and converts keys to camelCase for API compatibility.

## Parameters

  - `registration` - The current registration struct.

## Returns

  - A map representation of the registration.

---

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