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

export type StockType = 'good' | 'reject' | 'retail';

export type StokOpnameDraftData = {
    selectedProductId: string;
    physicalStocks: Record<string, Record<StockType, number>>;
    notes: string;
};

export const stokOpnameDraftStore =
    createDraftStore<StokOpnameDraftData>('stok-opname-draft');

export function saveStokOpnameDraft(
    type: 'create' | 'edit',
    data: StokOpnameDraftData,
    userId?: number,
): boolean {
    return stokOpnameDraftStore.save(type, data, userId);
}

export function loadStokOpnameDraft(
    type: 'create' | 'edit',
    userId?: number,
): StokOpnameDraftData | null {
    return stokOpnameDraftStore.load(type, userId);
}

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