Restaurant

%%{init: {'theme': 'base', 'themeVariables': {
            "fontSize": "20px",
            "background": "transparent",
            "actorBkg": "#038851",
            "actorTextColor": "#ffffff",
            "actorBorder": "#026139",
            "actorLineColor": "#94a3b8",
            "signalColor": "#64748b",
            "signalTextColor": "#059669",
            "noteBkgColor": "#e6f4ee",
            "noteTextColor": "#02502f",
            "noteBorderColor": "#038851",
            "activationBkgColor": "#c6ebdc",
            "activationBorderColor": "#026139",
            "sequenceNumberColor": "#ffffff"
     
}}}%%
sequenceDiagram
    autonumber
    actor Customer
    participant Channel as Ordering Channel
    participant Deliverect
    participant POS

    Note over Deliverect,POS: 1. Registration / Onboarding
    Note right of Deliverect: externalLocationId<br> is set in<br/>Deliverect location settings
    Deliverect->>POS: POST /register (accountId, locationId,<br/>externalLocationId, locationName)
    POS-->>Deliverect: 200 OK { ordersWebhookURL,<br/>syncProductsURL, syncTablesURL,<br/>syncFloorsURL, taxCalculationWebhookURL }
    Note right of Deliverect: Returned URLs<br>are saved<br/>in the location settings

    Note over Deliverect,POS: 2. Product Sync (user-initiated from Deliverect)
    Deliverect->>POS: GET /syncProducts?locationID=...
    alt Synchronous response
        POS-->>Deliverect: 200 OK (products & categories payload)
    else Asynchronous response
        POS-->>Deliverect: 204 No Content
        POS->>Deliverect: POST Insert/update products & categories
        Deliverect-->>POS: 200 OK
    end

    Note over Customer,POS: 3. Order Injection
    Customer->>Channel: Places an order
    Channel->>Deliverect: New order
    Deliverect->>POS: POST /orders (order webhook:<br/>items, prices, payment, customer)
    POS-->>Deliverect: 200 / 201 (within 30s)

    Note over Deliverect,POS: 4. Asynchronous Order Status Updates
    POS->>Deliverect: POST /orderStatus/{orderId} (status=ACCEPTED 20)
    Deliverect-->>POS: 200 OK
    Deliverect->>Channel: Relay status
    POS->>Deliverect: POST /orderStatus/{orderId} (status=PICKUP_READY 70)
    Deliverect-->>POS: 200 OK
    Deliverect->>Channel: Relay status
    POS->>Deliverect: POST /orderStatus/{orderId} (status=FINALIZED 90)
    Deliverect-->>POS: 200 OK

    Note over Deliverect,POS: 5. Cancellation (optional)
    Channel->>Deliverect: Cancellation request
    Deliverect->>POS: POST /orders (cancellation)
    POS->>Deliverect: POST /orderStatus/{orderId} (status=CANCELED 110)
    Deliverect-->>POS: 200 OK