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

export type CuttingDraftData = {
    productName: string;
    sample: number;
    originalOutsideSample: number;
    notes: string;
    materials: Array<{
        raw_material_price_id: number;
        material_usage: number;
        material_result: number | null;
        combination_index: number | null;
        variant: string;
        material_name: string;
        unit: string;
        photo_url: string | null;
    }>;
    combinations: Array<{
        material_result: number | null;
    }>;
    selectedMaterialName?: string;
    photo?: string;
};

export const cuttingDraftStore =
    createDraftStore<CuttingDraftData>('cutting-draft');

export function saveCuttingDraft(
    type: 'create' | 'edit',
    data: CuttingDraftData,
    userId?: number,
): boolean {
    return cuttingDraftStore.save(type, data, userId);
}

export function loadCuttingDraft(
    type: 'create' | 'edit',
    userId?: number,
): CuttingDraftData | null {
    return cuttingDraftStore.load(type, userId);
}

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