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

export type RawMaterialDraftData = {
    name: string;
    unit: string;
    isActive: boolean;
    variants: Array<{
        id?: number | null;
        variant: string;
        price: number;
        stock: number;
        photo?: string;
    }>;
};

export const rawMaterialDraftStore =
    createDraftStore<RawMaterialDraftData>('raw-material-draft');

export function saveRawMaterialDraft(
    type: 'create' | 'edit',
    data: RawMaterialDraftData,
    userId?: number,
    rawMaterialId?: number,
): boolean {
    return rawMaterialDraftStore.save(type, data, userId, rawMaterialId);
}

export function loadRawMaterialDraft(
    type: 'create' | 'edit',
    userId?: number,
    rawMaterialId?: number,
): RawMaterialDraftData | null {
    return rawMaterialDraftStore.load(type, userId, rawMaterialId);
}

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