@startuml


hidefootbox


title Client High Priority Messaging As Is/To Be

skinparam shadowing false

skinparam backgroundColor #f7f7f7

!define FONT_SIZE_1 17
!define FONT_SIZE_2 14
!define FONT_SIZE_3 13

!define FONT_NAME_1 SansSerif
!define FONT_NAME_2 SansSerif
!define FONT_NAME_3 SansSerif

skinparam sequenceActorBorderColor #black
skinparam defaultFontName FONT_NAME_2
skinparam defaultFontSize FONT_SIZE_2
skinparam defaultFontStyle plain

skinparam sequence {
    TitleFontName SansSerif
    TitleFontSize 21
    TitleFontStyle bold

    ActorBorderColor #1112299
    ArrowColor #222222
    ArrowFontName SansSerif
    ArrowFontSize 13
    ArrowFontStyle bold

    BoxBorderColor backgroundColor
    BoxBorderColor #454545
    BoxBorderThickness 1.1
    BoxFontSize 15
    BoxFontStyle bold
    BoxHeaderFontSize 14
    BoxHeaderFontStyle italic



    GroupBorderColor #454545
    GroupBorderThickness 1.1
    GroupFontSize 14
    GroupFontStyle italic
    GroupHeaderFontSize 14
    GroupHeaderFontStyle italic

    ReferenceFontSize 14
    ReferenceBorderThickness 1.1
    ReferenceBackgroundColor #e7e7e7

    ParticipantBorderColor #777777
    ParticipantBorderThickness 2.5
    ParticipantBackgroundColor #bfefff
    ParticipantFontName SansSerif
    ParticipantFontSize 17
    ParticipantFontStyle bold

    DividerBorderColor #777777
    DividerBorderThickness 1
    DividerBackgroundColor #f7f7f7
    DividerFontName SansSerif
    DividerFontSize 17
    DividerFontStyle bold
    


    LifelineBorderThickness 3
    LifelineBorderColor #7e7e7e
    LifelineBackgroundColor #cecece

    DividerBorderThickness 1

}


box "Vehicle"
participant HU
participant TBM


end box

box "backend"
participant "MQTT Broker" as broker
participant "SMS Service" as SMS
participant "SDP Vehicle Account Service" as VAS


participant "Remote Operations Service" as RO
note left of RO: Remote Operations are High Priority
participant "Send Destination Service" as SD
note right of RO: Send Destination is Low Priority


end box

box "Consuming API"
participant "Incoming API" as API
end box
autonumber 1 1
  

Ref over VAS, broker
Initialize As IS GROP
end

== Client Messaging High Priority ==

group Client Messaging
activate broker
activate RO
broker -> RO: Client ConnectionStatus
API -> RO: Incoming Request\n Send Destination Message\n for clientId (TBM0001)
RO -> RO: Is Client Connected?
alt ClientConnected
RO -> broker: Publish Message to FCASDP/TBM0001/RO/
TBM <-> broker: Receive Message from FCASDP/TBM0001/RO/
else else client not connected
RO -> broker: Store message
RO -> SMS: Request SMS
SMS -> TBM: Wake up SMS Sent to TBM Client
end
alt Connect with Clean Session Set to False
TBM -> broker: Connect and Subscribe
broker -> RO: Client connected
RO -> broker: Publish RO Request
else else client connects with cleanSession set to true
TBM -> broker: cleanSession(true)
broker -> broker: remove all messages from FCAROP/TBM0001/#
broker -> RO: client connected
note left of RO: There is no guarantee\n or means of mediating if\n the queue will be cleared\n before the RO services publishes
TBM -> broker: Subscribe to FCASDP/TBM0001/RO
RO -> broker: Publish Message to FCASDP/TBM0001/RO/
TBM <-> broker: Receive Message from FCASDP/TBM0001/RO/

end
end
alt Ghost Connection
== Server believes client is connected due to ungraceful disconnect due to coverage etc ==
alt Client Retry Connection with cleanSession(false)
RO -> broker: Publish Message to FCASDP/TBM0001/RO/
TBM -> broker: Connect to broker and subscribe to FCASDP/TBM0001/RO within seconds 
TBM <-> broker: Receive Message from FCASDP/TBM0001/RO/
else else Client Retry Connection with cleanSession(true)
RO -> broker: Publish Message to FCASDP/TBM0001/RO/
TBM -> broker: Connect cleanSession(true)
broker -> broker: Delete all messages under FCASDP/TBM0001/#
TBM -> broker: Subcribe to FCASDP/TBM0001/
note right of broker: No messages present to send to client
end

deactivate broker

end group





@enduml