@startuml

autonumber
title: Publish a Service on behalf of a delegator
header: Delegation

box "Delegatee"
    actor "User" as user
    participant "Contract Manager" as contractManagerDelegatee
end box

box "Directory"
    participant "Directory API" as directoryAPI
end box

box "Delegator"
    participant "Contract Manager" as contractManagerDelegator
end box

user -> contractManagerDelegatee: Get Contracts with __GrantDelegationServicePublication__
return Contracts
user -> contractManagerDelegatee: Create Contract for Service with \n__GrantDelegatedServicePublication__ based on __GrantDelegationServicePublication__
contractManagerDelegatee -> contractManagerDelegatee: Create contract\nwith __GrantDelegatedServicePublication__
contractManagerDelegatee -> contractManagerDelegatee: Accept contract
contractManagerDelegatee -> directoryAPI: Submit contract
directoryAPI -> directoryAPI: Check if Contract is not expired
directoryAPI -> directoryAPI: Check if Contract is not revoked or rejected
directoryAPI -> directoryAPI: Check if accept signature is present for Delegatee
directoryAPI -> directoryAPI: Check if serial number of Delegatee is equal to ""service.peer_serial_number"" of the __GrantDelegatedServicePublication__
directoryAPI -> contractManagerDelegator: Is delegatee of contract allowed to publish this service on behalf of you? \nGet Contract containing __GrantDelegateServicePublication__ which matches with the details of __GrantDelegatedServicePublication__.
return contract
directoryAPI -> directoryAPI: Check if Contract is not expired
directoryAPI -> directoryAPI: Check if Contract is not revoked or rejected
directoryAPI -> directoryAPI: Check if accept signature is present for Delegatee and Delegator
directoryAPI -> directoryAPI: Check if properties of the __GrantDelegatedServicePublication__ are equal to those of the __GrantDelegateServicePublication__
directoryAPI -> directoryAPI: Publish service
directoryAPI -> contractManagerDelegatee: return ok
contractManagerDelegatee -> user: return ok

skinparam sequenceBoxBorderColor #transparent
skinparam boxPadding 50
hide footbox
@enduml
