@startuml
title Email Admin Tenant Audit Hardening (After)

skinparam backgroundColor #FFFFFF
skinparam defaultFontColor #000000
skinparam ArrowColor #000000
skinparam SequenceLifeLineBorderColor #000000
skinparam SequenceLifeLineBackgroundColor #F7F7F7
skinparam ParticipantBorderColor #000000
skinparam ParticipantBackgroundColor #D9F2D9
skinparam NoteBackgroundColor #E9F7FF
skinparam NoteBorderColor #000000

actor "Tenant Admin" as Admin
participant "Axum dispatch\n(dispatch_auth_request)" as Dispatch
participant "AdminPlugin" as Plugin
participant "Audit metadata enricher\n(enrich_audit_metadata)" as Enricher
participant "Admin audit logger\n(write_audit)" as Audit
database "admin_audit_logs" as AuditTable
participant "Email handlers\n(template/failure update)" as Handlers

Admin -> Dispatch: /admin/email* request
Dispatch -> Dispatch: resolve tenant id
Dispatch -> Plugin: inject canonical request header\nx-athena-tenant=<resolved tenant>

Plugin -> Handlers: create/update email-template,\nemail-failure operations
Handlers -> Handlers: reject blank templateKey/subjectTemplate\ntrim nullable resolutionNote

Plugin -> Enricher: merge base context + route metadata
Enricher -> Enricher: reserve source/method/path/tenant\nprevent caller override
Enricher --> Audit: normalized metadata payload
Audit -> AuditTable: insert audit event
AuditTable --> Audit: persisted

note right of Enricher
Every admin audit now carries canonical\nsource + request path + method,\nplus tenant when header is present.
end note

@enduml
