import { ApiHelper } from '/js/util/api.js';
import { UJ } from '/js/util/uj.js';

export const ProductMainDataService = {
    GetList: async function (queryData) {
        let api = '/api/ProductMain/GetList';
        api = UJ.BindQueryString(api, queryData);
        return await ApiHelper.sendRequest(api, "GET");
    },
    Get: async function (id) {
        return (await ApiHelper.sendRequest(`/api/ProductMain/Get?id=${id}`, "GET"));
    },
    Create: async function (data) {
        return await ApiHelper.sendRequest('/api/ProductMain/Create', "POST", data);
    },
    Update: async function (data) {
        return await ApiHelper.sendRequest('/api/ProductMain/Update', 'PATCH', data);
    },
    Delete: async function (id) {
        return await ApiHelper.sendRequest(`/api/ProductMain/Delete?id=${id}`, "DELETE");
    },
    GetListWithStock: async function (queryData) {
        return await ApiHelper.sendRequest('/api/ProductMain/GetListWithStock', "POST", queryData);
    },
    GetRelations: async function (id, ownerStoreId) {
        return (await ApiHelper.sendRequest(`/api/ProductMain/GetRelations?id=${id}&ownerStoreId=${ownerStoreId}`, "GET")).data;
    },
    GetAvailableStockList: async function (productId, attrId) {
        return await ApiHelper.sendRequest(`/api/ProductMain/GetAvailableStockList?productId=${productId}&attrId=${attrId}`, "GET");
    }
}