import type { WsEventType, WsEventPayload } from "./index.js"

export const ShopWsEvent = {
    EVENT: "shop:event",
    DELIVERY_ACK: "shop:event:delivery-ack",
    DELIVERY_ACKNOWLEDGED: "shop:event:delivery-acknowledged",
} as const

export type ShopEventDeliveryAckView = "cashier" | "production"

export interface ShopEventDeliveryAckPayload {
    shopId: string
    eventId: string
    eventType: string
    entityId?: string | null
    orderId?: string | null
    orderItemId?: string | null
    view: ShopEventDeliveryAckView
    stationId?: string | null
    cashSessionId?: string | null
    createdAt: string
}

export type ShopEventWire<T extends WsEventType = WsEventType> = {
    shopId: string
    seq: string // BigInt -> string
    type: T
    payload: WsEventPayload<T>
    createdAt: string
}

/**
 * Event socket.io unique: "shop:event"
 * Payload = ShopEventWire (générique)
 */
export type ShopWsEvents = {
    [ShopWsEvent.EVENT]: ShopEventWire
    [ShopWsEvent.DELIVERY_ACK]: ShopEventDeliveryAckPayload
    [ShopWsEvent.DELIVERY_ACKNOWLEDGED]: ShopEventDeliveryAckPayload
}