import { Module, PisellCore, ModuleOptions } from '../../types';
import { BaseModule } from '../BaseModule';
import { OrderModuleAPI, CommitOrderParams, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, CheckoutOrderParams, CancelOrderParams, ChangeBookingStatusParams } from './types';
import { CartItem } from '../Cart/types';
import { type SubmitPayloadEnhancer } from './utils';
import type { OrderAmountSnapshot, AddProductBookingInput, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, OrderScanCodeResult, ReplaceTempOrderOptions } from './types';
import type { ICustomer } from '../AccountList/types';
import type { Discount } from '../Discount/types';
export declare class OrderModule extends BaseModule implements Module, OrderModuleAPI {
    protected defaultName: string;
    protected defaultVersion: string;
    private store;
    private request;
    private logger;
    private dbManager;
    private window;
    private cacheId;
    private salesSummaryModuleName;
    private rulesHooksOverride?;
    private orderHooks?;
    private otherParams?;
    /** 是否将 tempOrder 写入 localStorage；默认 true，SalesSdk 等内存态场景可关闭。 */
    private enableTempOrderPersist;
    /**
     * Populate `savedAmount` on each discount based on product-level discount details.
     * Only selected discounts get a non-zero value.
     */
    static populateSavedAmounts(productList: Array<Record<string, any>>, discountList: Array<Record<string, any>>): void;
    constructor(name?: string, version?: string);
    initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
    /**
     * 记录信息日志
     */
    private logInfo;
    /**
     * 记录警告日志
     */
    private logWarning;
    /**
     * 记录错误日志
     */
    private logError;
    private registerDiscountModules;
    private createDefaultRulesHooks;
    loadDiscountConfig(params: {
        customerId: number;
        action?: 'create' | 'edit';
        orderId?: number;
        apply?: boolean;
    }): Promise<Discount[]>;
    getDiscountList(): Discount[];
    scanCode(code: string, customerId?: number): Promise<OrderScanCodeResult>;
    applyDiscount(): void;
    initTempOrder(params: {
        cacheId?: string;
        salesSummaryModuleName?: string;
    }): void;
    private getTempOrderStorageKey;
    private restoreTempOrderFromStorage;
    /**
     * 运行时切换 tempOrder localStorage 持久化。
     *
     * @example
     * orderModule.setEnableTempOrderPersist(false);
     * orderModule.addProductToOrder(product); // 不会写入 localStorage
     */
    setEnableTempOrderPersist(enabled: boolean): void;
    /**
     * 读取当前是否启用 tempOrder localStorage 持久化。
     *
     * @example
     * if (orderModule.isTempOrderPersistEnabled()) {
     *   orderModule.persistTempOrder();
     * }
     */
    isTempOrderPersistEnabled(): boolean;
    persistTempOrder(): void;
    private createDefaultTempOrderInstance;
    private createExternalSaleNumber;
    private ensureExternalSaleNumber;
    private ensureRequestUniqueIdempotencyToken;
    hasLocalDatabase(): boolean;
    private buildLocalOrderRecord;
    getLocalOrderByOrderId(orderId: number | string): Promise<Record<string, any> | null>;
    getLocalOrderByOrderNumber(orderNumber: string): Promise<Record<string, any> | null>;
    getLocalOrderByExternalSaleNumber(externalSaleNumber: string): Promise<Record<string, any> | null>;
    saveDraft(): Promise<void>;
    private saveDraftInBackground;
    private hydrateTempOrderFromLocalRecord;
    private extractOrderIdFromSubmitResult;
    private calculatePaymentTotal;
    private calculatePaidPaymentSummary;
    private calculatePaymentServiceFee;
    private getPaymentTargetAmount;
    ensureTempOrder(): OrderTempOrder;
    restoreOrder(): OrderTempOrder;
    getTempOrder(): OrderTempOrder | null;
    replaceTempOrder(tempOrder: OrderTempOrder, options?: ReplaceTempOrderOptions): Promise<OrderTempOrder>;
    getOrderIdentity(): OrderIdentitySnapshot | null;
    getOrderSyncState(): OrderSyncState;
    getOrderAmountSnapshot(): OrderAmountSnapshot | null;
    getOrderSnapshot(): OrderSnapshot | null;
    addNewOrder(): Promise<OrderTempOrder>;
    getOrderProducts(): OrderProduct[];
    private getProductUid;
    private ensureExtend;
    private captureProductRuntime;
    private createLinkedProductAndBooking;
    private getBookingUniqueIdentificationNumber;
    private findBookingIndexByUniqueIdentificationNumber;
    private removeLinkedBookingsForProduct;
    private getSalesSummary;
    recalculateSummary(options?: {
        createIfMissing?: boolean;
    }): Promise<OrderSummary | null>;
    getOrderSummary(): Promise<OrderSummary>;
    updateTempOrderNote(note: string): string;
    updateTempOrderNote(note: string, sync: true): Promise<string>;
    updateTempOrderNote(note: string, sync: boolean): string | Promise<string>;
    syncTempOrderNoteToRemote(orderId: number | string, note: string): Promise<string>;
    getTempOrderNote(): string;
    updateTempOrderShopDiscount(amount: string | number): string;
    updateTempOrderBuzzer(buzzer: string): string;
    updateTempOrderContactsInfo(contactsInfo: Record<string, any> | null): Record<string, any> | null;
    private buildTempOrderCustomer;
    /**
     * 更新当前 tempOrder 的客户协议字段。
     *
     * PaymentModal 只需要修改订单里的客户事实；如果外部还有客户模块需要同步，
     * 应由调用方通过回调处理，不能把外部 UI 状态写进 tempOrder。
     */
    updateTempOrderCustomer(customer: UpdateTempOrderCustomerInput): OrderSnapshot['customer'];
    setOrderCustomer(patch: OrderCustomerPatch | null, snapshot?: ICustomer | null): void;
    getOrderCustomer(): OrderCustomerView | null;
    getOrderCustomerSnapshot(): ICustomer | null;
    clearOrderCustomer(): void;
    private emitOrderCustomerChange;
    /**
     * 读取当前订单的 Sales 协议支付项。
     *
     * 这里返回的是 tempOrder.payments，而不是旧 PaymentModule 的本地
     * payment order / tender session。Sales checkout 以该数组为提交事实来源。
     */
    getOrderPayments(): OrderPaymentData[];
    /**
     * 用一组支付来源覆盖当前订单支付项。
     *
     * 入参允许来自 PaymentModule 的 PaymentItem，内部统一映射为 Sales 协议：
     * uuid -> metadata.unique_payment_number，id -> custom_payment_id，
     * isSynced 等运行态字段不会进入 tempOrder.payments。
     */
    setOrderPayments(payments: OrderPaymentSource[]): OrderPaymentData[];
    /** 追加单个支付项，并立即持久化当前 tempOrder。 */
    addOrderPayment(payment: OrderPaymentSource): OrderPaymentData[];
    /**
     * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
     *
     * 该方法服务 PaymentModal 的 void / 编辑场景；更新 metadata 时会做浅合并，
     * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
     */
    updateOrderPayment(paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>): OrderPaymentData[];
    /** 从当前订单支付项中移除指定支付项。 */
    deleteOrderPayment(paymentIdentity: string | number): OrderPaymentData[];
    /**
     * 覆盖当前订单中的 wallet pass 支付项。
     *
     * 判断口径与 PaymentModal 保持一致：voucher_id 存在且不为 0 的支付项
     * 视为 wallet pass；其它支付项保持不变。
     */
    updateVoucherOrderPayments(payments: OrderPaymentSource[]): OrderPaymentData[];
    private shouldMergeProductToOrder;
    addProductToOrder(product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput): Promise<OrderProduct[]>;
    private hasGoodPassDiscount;
    updateOrderProduct(params: UpdateOrderProductParams): Promise<OrderProduct[]>;
    updateOrderProductQuantity(params: UpdateOrderProductQuantityParams): Promise<OrderProduct[]>;
    updateOrderBooking(params: UpdateOrderBookingParams): any[];
    removeProductFromOrder(identity: OrderProductIdentity): Promise<OrderProduct[]>;
    /**
     * 仅清空购物车行（products / bookings），不重置整单。
     * 用于「仅清空商品」；客户、备注、支付等协议字段保持不变。
     */
    clearOrderCartLines(): Promise<OrderTempOrder>;
    /**
     * 提交当前 Sales tempOrder。
     *
     * smallTicketDataFlag 用于 B 端 checkout 小票数据返回。PaymentModal 在支付提交时
     * 应传 1，确保 /order/sales/checkout 返回打印所需数据。
     */
    submitTempOrder<T = any>(params?: {
        cacheId?: string;
        platform?: string;
        businessCode?: string;
        channel?: string;
        type?: string;
        payments?: OrderPaymentSource[];
        paymentStatus?: SubmitSalesOrderParams['query']['payment_status'];
        smallTicketDataFlag?: number;
        enhancePayload?: SubmitPayloadEnhancer;
    }): Promise<T>;
    private markLocalOrderSynced;
    private isSubmitResponseRejected;
    private isSubmitErrorResponse;
    private extractSubmitErrorResponse;
    private logSubmitBackendRejected;
    syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
    createOrder(params: CommitOrderParams['query']): {
        type: "appointment_booking" | "virtual";
        platform: string;
        sales_channel: string;
        order_sales_channel: string;
        bookings: any[];
        shop_note: string;
        schedule_date: string;
        is_deposit: number;
        relation_products: any[];
        relation_forms: any[];
    };
    checkBeforeSubmitOrder(params: {
        cartItems: CartItem[];
        type: 'holder' | 'account';
    }): boolean;
    submitOrder(order: CommitOrderParams): Promise<void>;
    cancelOrder(params: CancelOrderParams): Promise<any>;
    changeBookingStatus(params: ChangeBookingStatusParams): Promise<any>;
    /**
     * Checkout 专用：创建订单到后端
     *
     * 专门为 Checkout 模块设计的订单创建方法，
     * 直接调用 /order/checkout 接口创建订单
     * 接收已经处理好的订单数据，无需再处理购物车
     *
     * @param params Checkout 订单参数（已处理的订单数据）
     * @returns 后端返回的订单数据（包含订单ID等）
     */
    createOrderByCheckout(params: CheckoutOrderParams): Promise<any>;
    submitSalesOrder<T = any>(params: SubmitSalesOrderParams): Promise<T>;
    /**
     * 发送支付链接邮件。
     *
     * 调用前必须已经有远端 order_id。BaseSales 会在需要时先提交本地订单，
     * OrderModule 只负责校验 order_ids 并调用 /order/batch-email。
     */
    sendCustomerPayLink<T = any>(params: SendCustomerPayLinkParams): Promise<T>;
    getOrderInfoByRemote(order_id: number): Promise<any>;
    /**
     * 把 sqlite / 后端返回的订单记录直接恢复为 tempOrder。
     *
     * 数据源应尽量返回 tempOrder 所需结构；这里仅做 SDK 运行必须字段兜底，
     * 例如数组字段、商品行唯一值、价格 metadata、summary 派生状态和 _extend。
     */
    hydrateTempOrderFromRecord(record: Record<string, any>, options?: {
        recalcOnHydrate?: boolean;
    }): Promise<OrderTempOrder>;
    private normalizeTempOrderForRuntime;
    private normalizeHydratedOrderProduct;
    getLastOrderInfo(): Record<string, any> | undefined;
    getOrderInfo(order_id: number): Promise<any>;
}
export type { UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';
