@startuml change_email_route_precedence_sequences
title Change Email POST - Core Route Takes Precedence

actor "Client" as Client
participant "AthenaAuth::handle_request_inner" as Pipeline
participant "Core dispatcher\nhandle_core_request" as Core
participant "UserManagementPlugin\non_request" as UserMgmt
participant "DatabaseAdapter" as DB

Client -> Pipeline: POST /change-email
Pipeline -> Core: match core routes first
Core -> DB: update_user(email=newEmail, email_verified=false)
DB --> Core: updated
Core --> Pipeline: 200 StatusResponse
note right of Pipeline
Plugin on_request is not reached for this request
because core matched first.
end note
Pipeline --> Client: 200

@enduml

@startuml change_email_route_precedence_sequences_verify
title Change Email Verify - Plugin Route Handles Token Verification

actor "Client" as Client
participant "AthenaAuth::handle_request_inner" as Pipeline
participant "Core dispatcher\nhandle_core_request" as Core
participant "UserManagementPlugin\non_request" as UserMgmt
participant "DatabaseAdapter" as DB

Client -> Pipeline: GET /change-email/verify?token=...
Pipeline -> Core: match core routes first
Core --> Pipeline: no match
Pipeline -> UserMgmt: on_request()
UserMgmt -> DB: get_verification_by_identifier(token)
UserMgmt -> DB: update_user(...) and delete_verification(...)
UserMgmt --> Pipeline: 200 StatusMessageResponse
Pipeline --> Client: 200

@enduml

