@startuml
autonumber
participant ag as "Buyer"
box Seller TMF646, Appointment
participant sts as "Search Time Slot"
participant a as "Appointment"

alt Appointment for Trouble Ticket before creation of Trouble Ticket
  ag -> sts: POST SearchTimeSlot(relatedEntity=product1,requestedTS=validFor.timePeriod1, relatedParty=buyer, category=beforeFaultTicket)
  note over ag, sts: Since the Product exists already, when the SearchTimeslot is created, the relatedEntity is set byRef.
else Appointment for Trouble Ticket after creation of Trouble Ticket
  ag -> sts: POST SearchTimeSlot(relatedEntity=troubleTicket1,requestedTS=validFor.timePeriod1, relatedParty=buyer, category=duringFaultTicket)
else Appointment for ProductOrder after ProductOrder creation
  ag -> sts: POST SearchTimeSlot(relatedEntity=productOrder1,requestedTS=validFor.timePeriod1, relatedParty=buyer, category=duringProductOrder)
else Appointment for ProductOrder before ProductOrder creation
  ag -> sts: POST SearchTimeSlot(relatedEntity=product1,requestedTS=validFor.timePeriod1, relatedParty=buyer, category=beforeProductOrder)
  note over ag, sts: Since the Product doesn't exist, when the SearchTimeslot is created, the relatedEntity is set byValue.
end
ag <- sts: 201 Created(acknowledged)
sts -> ag: SearchTimeSlotStateChangeEvent(inProgress)
sts -> ag: SearchTimeSlotStateAttributeValueChangeEvent(availableTS=validFor.startDateTime=2024-02-02T14:00:00,validFor.endDateTime=2024-02-02T15:00:00,...)
sts -> ag: SearchTimeSlotStateChangeEvent(done)
note over ag, sts: Customer/Agent choses the appointment at 2.2.2024, 14-15 h

alt Appointment for Trouble Ticket before creation of Trouble Ticket
  ag -> a: POST Appointment(relatedEntity=product1,validFor.startDateTime=2023-02-02T14:00:00,validFor.endDateTime=2023-02-02T15:00:00, category=beforeFaultTicket )
  note over ag, a: Since the Product exists already, when the Appointment is created, the relatedEntity is set byRef.
else Appointment for Trouble Ticket after creation of Trouble Ticket
  ag -> a: POST Appointment(relatedEntity=troubleTicket1,validFor.startDateTime=2023-02-02T14:00:00,validFor.endDateTime=2023-02-02T15:00:00, category=duringFaultTicket )
else Appointment for ProductOrder after ProductOrder creation
  ag -> a: POST Appointment(relatedEntity=productOrder1,validFor.startDateTime=2023-02-02T14:00:00,validFor.endDateTime=2023-02-02T15:00:00, category=duringProductOrder )
else Appointment for ProductOrder before ProductOrder creation
  ag -> a: POST Appointment(relatedEntity=product1,validFor.startDateTime=2023-02-02T14:00:00,validFor.endDateTime=2023-02-02T15:00:00, category=beforeProductOrder )
  note over ag, a: Since the Product doesn't exist, when the Appointment is created, the relatedEntity is set byValue.
end
ag <- a: 201 Created (initialized)
ag <- a: ApointmentStateChangeEvent(confirmed)
@enduml
