import { m, u as $ } from "./app-Bpb4394e.js";
import { useCoreStore as B } from "@feedmepos/mf-common";
import { useSnackbar as k } from "@feedmepos/ui-library";
const N = m((r, a) => {
  const s = $(), u = B(), i = k();
  return a.onError(async (e) => {
    e.name === "SvcForbiddenError" && (i == null || i.open({
      title: e.title,
      message: e.message,
      type: "error"
    }));
  }), {
    async readStockBalance() {
      const e = s.currentLocationDBName, t = `${r.inventoryBackendUrl}/${e}/stock-balance`;
      return await a.get(t);
    },
    async readSkuBalance() {
      var o;
      const e = s.currentLocationDBName, t = `${r.inventoryBackendUrl}/${e}/sku/balance`;
      return (((o = u.currentBusiness.value) == null ? void 0 : o.menuVersion) ?? "") === "v3" ? await a.get(t) : await a.get(`${t}?useInventoryDoc=true`);
    },
    async readSingleAdjustment(e) {
      const t = s.currentLocationDBName, n = `${r.inventoryBackendUrl}/${t}/adjustment`;
      return await a.get(`${n}?adjustmentId=${e}`);
    },
    async readStockAdjustment(e, t, n) {
      const o = s.currentLocationDBName, c = `${r.inventoryBackendUrl}/${o}/sku`;
      return await a.get(`${c}?skuId=${e}&start=${t}&end=${n}`);
    },
    async readAdjustmentById(e) {
      const t = s.currentLocationDBName, n = `${r.inventoryBackendUrl}/${t}/adjustment`;
      return await a.get(`${n}?adjustmentId=${e}`);
    },
    async convertSku(e) {
      var c;
      const t = s.currentLocationDBName, n = `${r.inventoryBackendUrl}/${t}/sku/convert`;
      return (((c = u.currentBusiness.value) == null ? void 0 : c.menuVersion) ?? "") === "v3" ? await a.post(n, e) : await a.post(`${n}?useInventoryDoc=true`, e);
    },
    async adjustSku(e) {
      var c;
      const t = s.currentLocationDBName, n = `${r.inventoryBackendUrl}/${t}/sku/adjust`;
      return (((c = u.currentBusiness.value) == null ? void 0 : c.menuVersion) ?? "") === "v3" ? await a.post(n, e) : await a.post(`${n}?useInventoryDoc=true`, e);
    },
    async revertWastageAdjustment(e) {
      const t = s.currentLocationDBName, n = `${r.inventoryBackendUrl}/${t}/sku/revert-wastage-adjustment`;
      return await a.post(n, e);
    },
    recalculation: {
      getRecalculateAbility() {
        var o;
        const t = `business_${(o = u.currentBusiness.value) == null ? void 0 : o._id}`, n = `${r.inventoryBackendUrl}/${t}/stock/operations/recalculate`;
        return a.get(n);
      },
      startRecalculateTask() {
        var o;
        const t = `business_${(o = u.currentBusiness.value) == null ? void 0 : o._id}`, n = `${r.inventoryBackendUrl}/${t}/stock/operations/recalculate?refundFromPreviousAdjustment=true`;
        return a.post(n);
      },
      refreshCurrentBalances() {
        const e = s.currentLocationDBName, t = `${r.inventoryBackendUrl}/${e}/stock/operations/recalculate/refresh-current-balances`;
        return a.post(t);
      },
      scheduleInvalidateClosingDraftCache(e) {
        const t = s.currentLocationDBName, n = `${r.inventoryBackendUrl}/${t}/stock/operations/recalculate/schedule/invalidate-closing-draft-cache`;
        return a.post(n, { closingDraftIds: e });
      },
      recalculationRequests() {
        const e = s.currentLocationDBName, t = `${r.inventoryBackendUrl}/${e}/stock/operations/recalculate/recalculation/requests`;
        return a.get(t);
      },
      scheduleRecalculation(e) {
        const t = s.currentLocationDBName, n = `${r.inventoryBackendUrl}/${t}/stock/operations/recalculate/schedule/recalculation`;
        return a.post(n, {
          openingId: e.openingId,
          untilDate: e.untilDate,
          recalculateBySnapshot: e.recalculateBySnapshot
        });
      },
      getAffectedClosingDrafts(e, t) {
        const n = s.currentLocationDBName, o = `${r.inventoryBackendUrl}/${n}/closing-draft/recalculation/affected-closing-drafts?openingId=${encodeURIComponent(e)}&untilDate=${encodeURIComponent(t)}`;
        return a.get(o);
      }
    },
    async readUnitCostHistory(e, t, n) {
      var d;
      const o = s.currentLocation.doc._id, c = ((d = u.currentBusiness.value) == null ? void 0 : d._id) ?? "", l = `${r.inventoryBackendUrl}/${c}/api/unit-cost-history`;
      return await a.get(
        `${l}?locationId=${o}&skuId=${e}&startDate=${t}&endDate=${n}`
      );
    }
  };
});
export {
  N as u
};
