import { api } from '$lib/api';
import type { Item } from './items';

export interface ItemPreset {
    id: number;
    tenant_id: number;
    company_id: number;
    name: string;
    description?: string;
    items: Item[];
    created_at?: string;
    updated_at?: string;
}

export interface ItemPresetCreate {
    name: string;
    description?: string;
    items: Item[];
}

export interface ItemPresetUpdate {
    name?: string;
    description?: string;
    items?: Item[];
}

export const itemPresetsApi = {
    /**
     * List all item presets for a company
     */
    list: (companyId: number) => {
        const params = new URLSearchParams({
            company_id: companyId.toString()
        });
        return api.get<ItemPreset[]>(`/v1/a76/item-presets/?${params.toString()}`);
    },

    /**
     * Get a specific item preset
     */
    get: (presetId: number, companyId: number) => {
        const params = new URLSearchParams({
            company_id: companyId.toString()
        });
        return api.get<ItemPreset>(`/v1/a76/item-presets/${presetId}/?${params.toString()}`);
    },

    /**
     * Create a new item preset
     */
    create: (companyId: number, data: ItemPresetCreate) => {
        const params = new URLSearchParams({
            company_id: companyId.toString()
        });
        return api.post<ItemPreset>(`/v1/a76/item-presets/?${params.toString()}`, data);
    },

    /**
     * Update an existing item preset
     */
    update: (presetId: number, companyId: number, data: ItemPresetUpdate) => {
        const params = new URLSearchParams({
            company_id: companyId.toString()
        });
        return api.put<ItemPreset>(`/v1/a76/item-presets/${presetId}/?${params.toString()}`, data);
    },

    /**
     * Delete an item preset
     */
    delete: (presetId: number, companyId: number) => {
        const params = new URLSearchParams({
            company_id: companyId.toString()
        });
        return api.delete(`/v1/a76/item-presets/${presetId}/?${params.toString()}`);
    }
};
