| 1 |
|
defmodule WalletLimitsFees.Events.PolicyDecisionCaptured do |
| 2 |
|
@moduledoc "Emitted when a policy evaluation decision is made (limits check or fee calculation)." |
| 3 |
|
@behaviour WalletEvents.DomainEvent |
| 4 |
|
|
| 5 |
|
@impl true |
| 6 |
:-( |
def event_name, do: "PolicyDecisionCaptured.v1" |
| 7 |
|
|
| 8 |
|
@impl true |
| 9 |
:-( |
def event_version, do: 1 |
| 10 |
|
|
| 11 |
|
@doc "Builds the domain event map." |
| 12 |
:-( |
def build(decision_type, outcome, opts \\ []) do |
| 13 |
:-( |
%{ |
| 14 |
|
event_id: WalletSharedKernel.Correlation.new_request_id(), |
| 15 |
|
event_name: event_name(), |
| 16 |
|
event_version: event_version(), |
| 17 |
|
aggregate_id: Keyword.get(opts, :transfer_id, "unknown"), |
| 18 |
|
correlation_id: |
| 19 |
|
Keyword.get(opts, :correlation_id, WalletSharedKernel.Correlation.new_correlation_id()), |
| 20 |
|
occurred_at: DateTime.utc_now(), |
| 21 |
|
payload: %{ |
| 22 |
|
decision_type: decision_type, |
| 23 |
|
outcome: inspect(outcome), |
| 24 |
|
tier: Keyword.get(opts, :tier), |
| 25 |
|
currency: Keyword.get(opts, :currency), |
| 26 |
|
amount: Keyword.get(opts, :amount), |
| 27 |
|
details: Keyword.get(opts, :details, %{}) |
| 28 |
|
} |
| 29 |
|
} |
| 30 |
|
end |
| 31 |
|
end |