import { DineroObject } from "dinero.js"; import { type BaseOrderOption, type Order, ORDER_TYPE, PAYMENT_TYPE } from "../order.interface"; import { type DeliveryTime } from "~backend/business/business.interface"; import { type OfflinePaymentType } from "~backend/business/business.model"; import { type OperatingHours } from "~backend/public-setting/public-setting.model"; /** * true choosen provider */ export declare enum DELIVERY_PROVIDER_TYPE { GRAB_EXPRESS = "GRAB_EXPRESS", PANDA_GO = "PANDA_GO", KOSMO = "KOSMO", IN_HOUSE = "IN_HOUSE", MANUAL = "MANUAL" } /** * data for front-end to pass in * choose inhouse or external delivery (aka FEEDME) */ export declare enum DELIVERY_TYPE { IN_HOUSE = "IN_HOUSE", FEEDME = "FEEDME" } /** * Available service for MANUAL provider */ export declare enum MANUAL_AVAILABLE_SERVICE { GRAB_EXPRESS = "GRAB_EXPRESS", PANDA_GO = "PANDA_GO", KOSMO = "KOSMO" } export declare enum DELIVERY_STATUS { /** * Active state where DO is in progress */ CREATING = "CREATING", NEW = "NEW", IN_DELIVERY = "IN_DELIVER", PICKING_UP = "PICKING_UP", IN_RETURN = "IN_RETURN", /** * End state where DO is end, no more edit should execute */ CANCELED = "CANCELED", RETURNED = "RETURNED", COMPLETE = "COMPLETE", FAILED = "FAILED", REFUSED = "REFUSED" } export declare enum DELIVERY_QUOTE_STATUS { SHOW = "SHOW", HIDDEN = "HIDDEN", DISABLED = "DISABLED" } export interface Coordinates { lat: number; lng: number; } export interface Address { addressLine: string; coordinates?: Coordinates; city?: string; } export interface Product { name: string; quantity: number; remark?: string; price: DineroObject; } export interface QuoteOption { restaurantId: string; destination: Address; products?: Product[]; } export interface QuoteLocationDetail { origin: Address; destination: Address; products?: Product[]; } export interface DeliveryRestaurant { id: string; address: Address; name?: string; phone?: string; email?: string; /** * instruction given by restaurant to driver */ instruction?: string; } export interface Receiver { id: string; name?: string; email?: string; phoneNumber?: string; address: Address; } export interface DeliveryDto { restaurant: DeliveryRestaurant; receiver: Receiver; selectedOption?: DELIVERY_TYPE; products?: Product[]; } export interface DeliveryQuote { deliveryType: DELIVERY_TYPE; term?: string; deliveryFee?: DineroObject; freeAfterTotal?: DineroObject | null; minPurchase?: DineroObject | null; quoteStatus: DELIVERY_QUOTE_STATUS; paymentTypes: PAYMENT_TYPE[]; offlinePaymentTypes?: OfflinePaymentType[]; deliveryTime: DeliveryTime | null; availableHours: OperatingHours | null; } export interface Vehicle { licensePlate: string; model: string; physicalVehicleType: string; } export interface Driver { name: string; phone: string; pictureURL?: string; coordinates?: Coordinates; vehicle: Vehicle; } export interface QuoteDeliveryFee { providerType: DELIVERY_PROVIDER_TYPE; providerQuote: DineroObject; surcharge: DineroObject; total: DineroObject; } export interface BaseDeliveryOption extends BaseOrderOption { type: ORDER_TYPE.DELIVERY; contactNumber: string; addressLine: string; lat: number; lng: number; /** * deprecated, only exist for old system */ deliveryFee: DineroObject; quoteDeliveryFee?: QuoteDeliveryFee; deliveryType?: DELIVERY_TYPE; /** * deprecated, only exist for old system */ status: DELIVERY_STATUS; remark?: string; deliveryAt: string; /** * Indicate the time and date where driver start allocating */ allocatingAt?: Date; /** * List of delivery providers for current order, * First provider created when POS call driver * the provider will update through cron job and webhook, * every time update will check the delivery status * (for the delivery status and the delivery flow, check the order readme file) * * If the delivery status fail, new provider will created and push to this array * Failed delivery will still exist in the provider list, * but will not update by webhook or cron job anymore. * * Only one active provider (which can be update by webhook or cron job) will exist in one order at a time. */ providers?: T[]; } export interface DeliveryOption extends BaseDeliveryOption { } export interface GeneralDeliveryOption extends BaseDeliveryOption { deliveryType?: DELIVERY_TYPE; } export interface GeneralProvider { type: DELIVERY_PROVIDER_TYPE; } export type DeliveryProvider = GrabExpressProvider | KosmoProvider | PandaGoProvider | KosmoProvider | ManualProvider; export interface WebhookResponses { date: Date; body: any; } /** * Define the delivery service is provided by which company and the related detail, * Such as delivery fee, delivery type, status, etc */ export interface BaseProvider extends GeneralProvider { driver?: Driver; type: DELIVERY_PROVIDER_TYPE; deliveryId?: string; webhookResponses: WebhookResponses[]; deliveryFee?: DineroObject; origin: Address; phone: string; status: DELIVERY_STATUS; trackingUrl?: string; /** * instruction given by restaurant to the driver */ instruction?: string; /** * useful infomation for driver to pickup the order * example: for grab will be some pin like 1099 */ pickupRef?: string; } export interface GrabExpressProvider extends BaseProvider { type: DELIVERY_PROVIDER_TYPE.GRAB_EXPRESS; } export interface PandaGoProvider extends BaseProvider { type: DELIVERY_PROVIDER_TYPE.PANDA_GO; } export interface KosmoProvider extends BaseProvider { type: DELIVERY_PROVIDER_TYPE.KOSMO; } export interface ManualProvider extends BaseProvider { type: DELIVERY_PROVIDER_TYPE.MANUAL; choosenService?: MANUAL_AVAILABLE_SERVICE; /** * package remark, can be the package id */ remark?: string; } export type ProviderUpdate = Partial; export interface DataChangedOnWebhook { status: DELIVERY_STATUS; providerUpdate: ProviderUpdate; } export type DOCreatedData = Pick & Omit; export type QuotedResult = { quoteDeliveryFee: DineroObject; surcharge: DineroObject; }; export interface DeliveryCancelDto { orderId: string; deliveryId: string; retry?: boolean; order?: Order; }