import { createDraftStore } from '@/lib/draft-store';

export type TransactionDraftData = {
    stockType: 'good' | 'reject';
    channel: string;
    priceType: string;
    paymentType: string;
    customerId: number | null;
    marketingId: number | null;
    discount: number;
    negoPrice: number | null;
    isCompleted: boolean;
    isAffiliate: boolean;
    tiktokOrderId: string;
    shopeeOrderId: string;
    selectedProductId: string;
    quantities: Record<string, number>;
    notes: string;
    photo?: string;
};

export const transactionDraftStore =
    createDraftStore<TransactionDraftData>('transaction-draft');

export function saveTransactionDraft(
    type: 'create' | 'edit',
    data: TransactionDraftData,
    userId?: number,
): boolean {
    return transactionDraftStore.save(type, data, userId);
}

export function loadTransactionDraft(
    type: 'create' | 'edit',
    userId?: number,
): TransactionDraftData | null {
    return transactionDraftStore.load(type, userId);
}

export function clearTransactionDraft(
    type: 'create' | 'edit',
    userId?: number,
): void {
    transactionDraftStore.clear(type, userId);
}
