@startuml
!include theme.puml
title Order State Diagram

state ShopAPI {
    [*] --> AddingItems: addItemToOrder
    state AddingItems {
        AddingItems: Customer adds items to the order
        AddingItems: Customer details are set
        AddingItems: Shipping destination is set
        AddingItems: Shipping method is selected
    }

    state ArrangingPayment {
        ArrangingPayment: Payment provider is used to take payment
    }
}

state AdminAPI #f9c876 {
    state PaymentAuthorized {
        PaymentAuthorized: The payment has been authorized by the
        PaymentAuthorized: payment provider.
    }

    state PaymentSettled {
        PaymentSettled: The payment has been settled with the payment
        PaymentSettled: provider, i.e. the transaction is complete.
    }

    state PartiallyShipped {
        PartiallyShipped: Some, but not all, OrderItems have been shipped to the Customer
    }

    state Shipped {
        Shipped: All OrderItems have been shipped to the Customer
    }

    state PartiallyDelivered {
        PartiallyDelivered: Some, but not all, OrderItems have arrived with the Customer
    }

    state Delivered #9d9 {
        Delivered: All OrderItems have arrived with the Customer
    }


    state Cancelled #d99 {
        Cancelled: All OrderItems in the Order have been cancelled
    }
    Cancelled --> [*]

    Delivered --> [*]
}


AddingItems -> ArrangingPayment: transitionOrderToState
ArrangingPayment -> AddingItems: transitionOrderToState
ArrangingPayment -> PaymentAuthorized: addPaymentToOrder
ArrangingPayment --> PaymentSettled: addPaymentToOrder
PaymentAuthorized -> PaymentSettled: settlePayment
PaymentSettled -> Shipped: addFulfillmentToOrder, transitionFulfillmentToState
PaymentSettled --> PartiallyShipped: addFulfillmentToOrder, transitionFulfillmentToState
Shipped --> PartiallyDelivered: transitionFulfillmentToState
Shipped -> Delivered: transitionFulfillmentToState
PartiallyShipped --> Shipped: transitionFulfillmentToState
PartiallyDelivered --> Delivered: transitionFulfillmentToState

PaymentAuthorized --> Cancelled: cancelOrder
PaymentSettled --> Cancelled
Shipped --> Cancelled
PartiallyShipped --> Cancelled
PartiallyDelivered --> Cancelled
Delivered --> Cancelled



@enduml
