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

export type ProductDraftData = {
    productName: string;
    status: string;
    description: string;
    categoryIds: number[];
    useSamePrice: boolean;
    sharedPrices: Array<{ type: string; price: number }>;
    variants: Array<{
        id?: number | null;
        name: string;
        stock: number;
        reject_stock: number;
        retail_stock: number;
        photos?: Array<{ key: string }>;
        photo?: string;
        prices: Array<{ type: string; price: number }>;
    }>;
};

export const productDraftStore =
    createDraftStore<ProductDraftData>('product-draft');

export function saveProductDraft(
    type: 'create' | 'edit',
    data: ProductDraftData,
    userId?: number,
    productId?: number,
): boolean {
    return productDraftStore.save(type, data, userId, productId);
}

export function loadProductDraft(
    type: 'create' | 'edit',
    userId?: number,
    productId?: number,
): ProductDraftData | null {
    return productDraftStore.load(type, userId, productId);
}

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