@startuml
title Email Admin Create + Audit Targeting (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 "AdminPlugin\n/email/create\n/email-failure/create" as Plugin
participant "Admin handlers" as Handlers
participant "DatabaseAdapter\ncreate_*_record()" as Adapter
database "emails / email_send_failures" as Tables
database "admin_audit_logs" as Audit

Admin -> Plugin: POST create request
Plugin -> Handlers: validate + normalize
Handlers -> Adapter: create_*_record() -> created row
Adapter -> Tables: INSERT ... RETURNING *
Tables --> Adapter: created row (id + timestamps)
Adapter --> Handlers: created entity
Handlers --> Plugin: created entity response
Plugin -> Audit: write_audit(target_id = created.id)
Plugin --> Admin: 200 + created entity payload

note right of Plugin
Create CRUD responses now include generated IDs,\nand audit logs point to exact created resources\nper tenant runtime.
end note

@enduml
