# `MishkaPay.Meter`
[🔗](https://github.com/mishka-group/mishka_pay/blob/v0.0.1/lib/mishka_pay/meter.ex#L5)

A meter counts what customers use, for prices billed by usage (`mtr_...` at Stripe). A
guarded_struct.

Made with `MishkaPay.create_meter/1`, listed with `MishkaPay.list_meters/3`, turned off with
`MishkaPay.deactivate_meter/3` (a provider never deletes one). Usage reaches it with
`MishkaPay.report_usage/1` under its `:event_name`, and a price bills it with `:meter_id` and an
`:interval` (`MishkaPay.create_price/1`).

What the caller gives:

  * `:provider`, `:tenant`: which provider, with whose keys.
  * `:name`: the meter's name, for the seller only.
  * `:event_name`: the name usage is reported under, such as `"api_call"`.
  * `:aggregation`: how a period's usage adds up: `:sum` (the default) of the values, `:count`
    of the reports, or the `:last` value reported.

What the provider fills in: `:id`, `:status` (`:active` or `:inactive`) and `:created_at`.

# `t`

```elixir
@type t() :: %MishkaPay.Meter{
  aggregation: (:sum | :count | :last) | nil,
  created_at: DateTime.t() | nil,
  event_name: String.t() | nil,
  id: String.t() | nil,
  name: String.t() | nil,
  provider: String.t() | nil,
  status: (:active | :inactive) | nil,
  tenant: term() | nil
}
```

The struct that `builder/1` returns.

| Field | Type | Required | Default | Description | Derives |
| --- | --- | --- | --- | --- | --- |
| `:provider` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty)` |
| `:tenant` | `term()` \| `nil` | no |  |  |  |
| `:id` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:name` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty, max_len=250)` |
| `:event_name` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty, max_len=100)` |
| `:aggregation` | `:sum` \| `:count` \| `:last` \| `nil` | no | `:sum` |  | `validate(not_nil_value, enum=Atom[sum::count::last])`<br>validator `{MishkaPay.Meter, :aggregation}` |
| `:status` | `:active` \| `:inactive` \| `nil` | no |  |  | `validate(enum=Atom[active::inactive])` |
| `:created_at` | `DateTime.t()` \| `nil` | no |  |  | `validate(struct)` |

# `builder`

# `enforce_keys`

# `enforce_keys`

# `example`

A sample %MishkaPay.Meter{} populated from defaults + type-based fallbacks.

# `keys`

# `keys`

---

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