import { Response } from "express";
import CONSTANTS from "../config/constants";
import log from "../config/log";
import CustomRequest from "../types/requestType";
import { isUserPartner } from "../utils/isUserPartner";
import staffDB from "../models/staff.model";
import foodDB from "../models/food.model";
import occupancyDB from "../models/occupancy.model";
import moveOutDB from "../models/moveOut.model";
import moment from "moment";
import fsPromises from "fs/promises";
import fs from "fs";
import kitchenInventoryDB from "../models/kitchenInventory.model";
import propertyDB from "../models/property.model";
import propertiesTypes from "../schemas/property.schema";
import expenseDB from "../models/expense.model";
import { convertKitchenExpense } from "../utils/convertTypes";

const kitchenInventory: any = {};

kitchenInventory.AddItem = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "AddItem";

  try {
    const { categoryId, name, unitType } = req.body;

    log.info(
      `[${C}], [${F}], Category Id [${categoryId}], Product Name [${name}], Unit Type [${unitType}]`,
    );

    const userType = req.userType;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    const itemByName = await kitchenInventoryDB.getKitchenInventoryItemByName({
      clientId,
      name,
    });
    
    if (itemByName) {
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Name [${name}], Item Already Exsits With Same Name`
      );

      return res.status(400).json({
        msg: "Item already exsits with same name",
        isSuccess: false,
      });
    }

    await kitchenInventoryDB.addItem({
      clientId,
      categoryId,
      name,
      unitType,
      status: CONSTANTS.KITCHEN_ITEM_STATUS.ACTIVE,
    });

    log.info(
      `[${C}], [${F}], Category Id [${categoryId}], Product Name [${name}], Unit Type [${unitType}], Kitchen Item Added Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen item added successfully",
      isSuccess: true,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.AddPurchaseRecord = async (
  req: CustomRequest,
  res: Response,
) => {
  const C = "Inventory Controller";
  const F = "AddPurchaseRecord";

  const file = req.file as Express.Multer.File;
  const removeTmpImages = async () => {
    try {
      await fsPromises.unlink(file.path);
    } catch (err) {
      log.info(
        `[${C}], [${F}], Error in Removing Temp Image, Error [${JSON.stringify(
          err
        )}]`
      );
    }
  };

  try {
    let { vendorId, purchaseDate, description, invoiceNo, items, } = req.body;

    // Parse the JSON string sent via multipart/form-data
    if (typeof items === "string") {
      try {
        items = JSON.parse(items);
      } catch (parseErr) {
        await removeTmpImages();
        return res.status(400).json({
          msg: "Invalid items payload format",
          isSuccess: false,
        });
      }
    }

    if (!Array.isArray(items) || items.length === 0) {
      await removeTmpImages();
      return res.status(400).json({
        msg: "Items list cannot be empty",
        isSuccess: false,
      });
    }

    vendorId = vendorId ? Number(vendorId) : null;
    // itemId = Number(itemId);
    // quantity = Number(quantity);
    // cost = Number(cost);

    log.info(
      `[${C}], [${F}], Vendor Id [${vendorId}], Items [${JSON.stringify(items)}], Purchase Date [${purchaseDate}], Description [${description}], Invoice No [${invoiceNo}]`,
    );

    const userType = req.userType;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        await removeTmpImages();
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    let url = null;

    if (file) {
      const folderName = `kitchen_inventory_invoices`;
      const folderPath = `uploads/documents/client_${clientId}/${folderName}`;
      const fileExtension = file.mimetype.split("/")[1];
      const formattedDate = moment(purchaseDate).format("DDMMYYYY") + moment().format("HHmmss");
      const filename = `invoice(${req.id}${formattedDate}).${fileExtension}`;

      if (!fs.existsSync(folderPath)) {
        await fsPromises.mkdir(folderPath, { recursive: true });
      }

      const oldPath = `uploads/tmp/${file.filename}`;
      const newPath = `${folderPath}/${filename}`;
      url = `${process.env.UPLOAD_PATH}/documents/client_${clientId}/${folderName}/${filename}`;

      await fsPromises.copyFile(oldPath, newPath);

      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Old Path [${oldPath}], New Path [${newPath}], Url [${url}], Invoice Saved in DB.`
      );
    }

    if (Array.isArray(items) && items.length > 0) {
      for (let item of items) {
        const itemId = Number(item.itemId);
        const quantity = Number(item.quantity);
        const cost = Number(item.cost);

        const inventoryRecord = await kitchenInventoryDB.getInventoryRecordByClientIdAndItemId({
          clientId,
          itemId,
        });

        if (!inventoryRecord) {
          const inventoryRecordId = await kitchenInventoryDB.addInventoryRecord({
            clientId,
            itemId,
            currentCount: quantity,
          });

          await kitchenInventoryDB.updateInventoryTotalPurchased({
            id: inventoryRecordId,
            totalPurchased: cost,
          });

          await kitchenInventoryDB.updateInventoryCurrentValue({
            id: inventoryRecordId,
            currentValue: cost,
          });
        } else {
          await kitchenInventoryDB.updateInventoryRecord({
            id: inventoryRecord.id,
            currentCount: Number(inventoryRecord.currentCount) + Number(quantity),
          });

          await kitchenInventoryDB.updateInventoryTotalPurchased({
            id: inventoryRecord.id,
            totalPurchased: Number(inventoryRecord.totalPurchased || 0) + Number(cost),
          });

          await kitchenInventoryDB.updateInventoryCurrentValue({
            id: inventoryRecord.id,
            currentValue: Number(inventoryRecord.currentValue || 0) + Number(cost),
          });
        }

        const itemRecord = await kitchenInventoryDB.getInventoryItemById({
          id: itemId,
        });

        const purchaseRecord = await kitchenInventoryDB.addPurchaseRecord({
          categoryId: itemRecord.categoryId,
          itemId: itemRecord.id,
          clientId,
          vendorId: vendorId || null,
          price: Number(cost),
          quantity: Number(quantity),
          unitType: itemRecord.unitType,
          purchaseDate: purchaseDate,
          invoiceNo: invoiceNo || null,
          recordedBy: Number(userType) === CONSTANTS.USER_TYPE.CLIENT ? 0 : req.id,
          description,
          invoice: url,
        });

        if (!invoiceNo || invoiceNo.trim() === "" || invoiceNo.trim().toLowerCase() === "null" || invoiceNo.trim().toLowerCase() === "undefined") {
          invoiceNo = `INV${purchaseRecord}`;
          await kitchenInventoryDB.updateInvoiceNo({
            id: purchaseRecord,
            invoiceNo: invoiceNo,
          });
        }

        const expenseType = convertKitchenExpense(
          itemRecord.categoryId,
        )

        const expenseId = await expenseDB.create({
          type: expenseType,
          amount: cost,
          clientId,
          paidDate: purchaseDate,
          paidByUserType: req.userType,
          paidBy: req.id,
          paidTo: vendorId,
          paidToUserType: CONSTANTS.USER_TYPE.VENDOR,
          description,
          paymentMethod: CONSTANTS.TRANSACTION_MODES.OFFLINE,
          repetitionType: CONSTANTS.REPETITION_TYPE.ONE_TIME,
          noOfMonths: 0,
          dueDate: purchaseDate,
          isPaid: 1,
          paymentAccountNo: null,
          paymentAccountName: null,
          assetId: null,
          expenseNature: CONSTANTS.EXPENSE_NATURE.OPERATING,
          expenseTitle: `Purchase of ${itemRecord.name}`,
        });
      }
    }
    await removeTmpImages();

    log.info(
      `[${C}], [${F}], Items [${JSON.stringify(items)}], Purchase Date [${purchaseDate}], Description [${description}], Invoice No [${invoiceNo}], Kitchen Item Purchase Recorded Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen purchase recorded successfully",
      isSuccess: true,
    });
  } catch (error: any) {
    await removeTmpImages();
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.AssignInventoryItem = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "AssignInventoryItem";

  try {
    const { items, assignedTo } = req.body;

    log.info(
      `[${C}], [${F}], Items [${JSON.stringify(items)}], Assigned To [${assignedTo}]`,
    );

    const userType = req.userType;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    let lastTransferId = await kitchenInventoryDB.getLastDistributionTrasferId();
    if (!lastTransferId) lastTransferId = 1;

    let transferId = lastTransferId + 1;

    if (items && items.length > 0) {
      for (let item of items) {
        const inventoryId = Number(item.inventoryId);
        const quantity = Number(item.quantity);
        const inventoryRecord = await kitchenInventoryDB.getInventoryRecordById({
          id: inventoryId,
        });
    
        if (!inventoryRecord) {
          log.info(`[${C}], [${F}], Inventory Id [${inventoryId}], No Inventory Record Found`);
          return res.status(400).json({
            msg: CONSTANTS.MSG.INVALID_REQUEST,
            isSuccess: false,
          });
        }
    
        if (Number(inventoryRecord.currentCount) < Number(quantity)) {
          log.info(`[${C}], [${F}], Inventory Id [${inventoryId}], Insufficient Quantity`);
          return res.status(400).json({
            msg: CONSTANTS.MSG.INVALID_REQUEST,
            isSuccess: false,
          });
        }
    
        const currentCount = Number(inventoryRecord.currentCount || 0);
        const requestedQuantity = Number(quantity || 0);
    
        let purchaseRecords = await kitchenInventoryDB.getPurchaseRecordsByItemId({
          itemId: inventoryRecord?.itemId,
        });
    
        let assignedPrice = 0;
    
        if (purchaseRecords && purchaseRecords.length > 0) {
          // 1. Calculate historical consumption (Total Bought - Current Stock)
          const totalPurchased = purchaseRecords.reduce(
            (sum: any, record: any) => sum + Number(record.quantity || 0),
            0
          );
    
          // Edge Case 2: Inconsistent DB data safety check
          let consumedInPast = Math.max(0, totalPurchased - currentCount);
          let remainingToAssign = requestedQuantity;
    
          // 2. Iterate through batches in FIFO order
          for (const record of purchaseRecords) {
            if (remainingToAssign <= 0) break;
    
            const batchQty = Number(record.quantity || 0);
            const batchPrice = Number(record.price || 0);
    
            if (batchQty <= 0) continue;
    
            // Fast-forward past batches that are already consumed
            if (consumedInPast >= batchQty) {
              consumedInPast -= batchQty;
              continue;
            }
    
            // Available count in this specific active batch
            const availableInBatch = batchQty - consumedInPast;
            consumedInPast = 0; // Past consumption offset cleared
    
            // Take the smaller of what's available in this batch OR what we still need
            const takeFromBatch = Math.min(availableInBatch, remainingToAssign);
    
            // assignedPrice += Math.ceil(takeFromBatch * (batchPrice / record.quantity));
            assignedPrice += Number((takeFromBatch * (batchPrice / record.quantity)).toFixed(2));
            remainingToAssign -= takeFromBatch;
          }
        }
    
        const recordId = await kitchenInventoryDB.assignItem({
          inventoryId,
          clientId,
          quantity,
          assignedTo,
          assignedBy: Number(userType) === CONSTANTS.USER_TYPE.CLIENT ? 0 : req.id,
          assignedPrice,
        });

        await kitchenInventoryDB.updateDistributionTrasferId({
          id: recordId,
          transferId,
        })
    
        await kitchenInventoryDB.updateInventoryRecord({
          id: inventoryRecord.id,
          currentCount: Number(inventoryRecord.currentCount) - Number(quantity),
        });
        
        await kitchenInventoryDB.updateInventoryCurrentValue({
          id: inventoryRecord.id,
          currentValue: Number(inventoryRecord.currentValue || 0) - Number(assignedPrice) > 0 ? Number(inventoryRecord.currentValue || 0) - Number(assignedPrice) : 0,
        });
    
        log.info(
          `[${C}], [${F}], Client Id [${clientId}], Inventory Id [${inventoryId}], Quantity [${quantity}], Assigned To [${assignedTo}], Kitchen Item Assigned Successfully`,
        );
      }
    }

    log.info(`[${C}], [${F}], Client Id [${clientId}], Items [${JSON.stringify(items)}], Assigned To [${assignedTo}]`);

    return res.status(200).json({
      msg: "Kitchen item assigned successfully",
      isSuccess: true,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.ListInventoryItems = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "ListInventoryItems";

  try {
    const { pageNum, s } = req.query;

    log.info(`[${C}], [${F}], Search Value [${s}] Page Number [${pageNum}]`)

    const userType = req.userType;
    const limit = 10;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    let inventoryItems = []

    if (s && String(s).trim() !== "" && String(s).toLowerCase().trim() !== "null" && String(s).trim() !== "undefined") {
      inventoryItems = await kitchenInventoryDB.getItemsByClientIdAndSearch({
        clientId,
        searchVal: String(s),
        pageNum,
        limit,
      });      
    } else {
      inventoryItems = await kitchenInventoryDB.getItemsByClientId({
        clientId,
        pageNum,
        limit,
      });
    }


    // log.info(`Inventory Items [${JSON.stringify(inventoryItems)}]`);

    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Page Number [${pageNum}], Inventory Items Listed Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen items listed successfully",
      isSuccess: true,
      items: inventoryItems || [],
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.InventoryItemsEdit = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "InventoryItemsEdit";

  try {
    const { itemId, name, categoryId, unitType } = req.body;

    log.info(`[${C}], [${F}], Item Id [${itemId}], Name [${name}], Category Id [${categoryId}], Unit Type [${unitType}]`)

    const userType = req.userType;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    const itemRecord = await kitchenInventoryDB.getInventoryItemById({
      id: itemId,
    });

    if (!itemRecord) {
      log.info(`[${C}], [${F}], Item Id [${itemId}], No Item Found`);
      return res.status(400).json({
        msg: CONSTANTS.MSG.INVALID_REQUEST,
        isSuccess: false,
      });
    }

    const itemByName = await kitchenInventoryDB.getKitchenInventoryItemByNameForEdit({
      clientId,
      name,
    });
    
    if (itemByName) {
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Name [${name}], Item Already Exsits With Same Name`
      );

      return res.status(400).json({
        msg: "An item already exsits with same name",
        isSuccess: false,
      });
    }

    await kitchenInventoryDB.updateInventoryItemRecord({
      id: itemId,
      name,
      categoryId,
      unitType,
    });

    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Item Id [${itemId}], Item Name [${name}], Item Category [${categoryId}], Item Unit Type [${unitType}], Inventory Item Updated Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen item updated successfully",
      isSuccess: true,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.InventoryItemsDelete = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "InventoryItemsDelete";

  try {
    const { itemId } = req.body;

    log.info(`[${C}], [${F}], Item Id [${itemId}]`)

    const userType = req.userType;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    const itemRecord = await kitchenInventoryDB.getInventoryItemById({
      id: itemId,
    });

    if (!itemRecord) {
      log.info(`[${C}], [${F}], Item Id [${itemId}], No Item Found`);
      return res.status(400).json({
        msg: CONSTANTS.MSG.INVALID_REQUEST,
        isSuccess: false,
      });
    }

    await kitchenInventoryDB.updateInventoryItemStatus({
      id: itemId,
      status: CONSTANTS.KITCHEN_ITEM_STATUS.DELETED,
    });

    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Item Id [${itemId}], Inventory Item Deleted Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen item deleted successfully",
      isSuccess: true,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.kitchenDashboard = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "kitchenDashboard";

  try {
    let { categoryFilters, stockFilter } = req.query;

    log.info(`[${C}], [${F}], Category Filter [${categoryFilters}], Stock Filter [${stockFilter}]`);

    if (categoryFilters && typeof categoryFilters === 'string') {
      categoryFilters = categoryFilters.split(',').map(v => v.trim()).filter(Boolean);
    }

    const userType = req.userType;
    const limit = 10;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    let inventoryStocks = await kitchenInventoryDB.getInventoryStockByClientId({
      clientId,
      categoryFilters,
      stockFilter,
      pageNum: 1,
      limit: 5,
    });

    let lowInventoryStocks = await kitchenInventoryDB.getInventoryStockByClientId({
      clientId,
      categoryFilters,
      stockFilter: "LS",
      pageNum: 1,
      limit: 5,
    });

    let noInventoryStocks = await kitchenInventoryDB.getInventoryStockByClientId({
      clientId,
      categoryFilters,
      stockFilter: "OOS",
      pageNum: 1,
      limit: 5,
    });

    // log.info(`Inventory Stocks [${JSON.stringify(inventoryStocks)}], Low Inventory Stocks [${JSON.stringify(lowInventoryStocks)}], No Inventory Stocks [${JSON.stringify(noInventoryStocks)}]`);
    
    const inventoryItems = await kitchenInventoryDB.getInventoryItemsByClientIdForDropdown({
      clientId,
    });

    // log.info(`Inventory Items [${JSON.stringify(inventoryItems)}]`);

    const monthStockPurchaseAmount = await kitchenInventoryDB.getInventoryStockPurchaseAmountByDateRange({
      clientId,
      startDate: moment().startOf('month').format('YYYY-MM-DD'),
      endDate: moment().endOf('month').format('YYYY-MM-DD'),
    });

    const todayStockPurchaseAmount = await kitchenInventoryDB.getInventoryStockPurchaseAmountByDateRange({
      clientId,
      startDate: moment().format('YYYY-MM-DD'),
      endDate: moment().format('YYYY-MM-DD'),
    });

    // log.info(
    //   `Month Stock Purchase Amount [${monthStockPurchaseAmount}], Today Stock Purchase Amount [${todayStockPurchaseAmount}]`
    // );

    const thisMonthAssignedAmount = await kitchenInventoryDB.getInventoryAssignedAmountByDateRange({
      clientId,
      startDate: moment().startOf('month').format('YYYY-MM-DD'),
      endDate: moment().endOf('month').format('YYYY-MM-DD'),
    });

    const todayAssignedAmount = await kitchenInventoryDB.getInventoryAssignedAmountByDateRange({
      clientId,
      startDate: moment().format('YYYY-MM-DD'),
      endDate: moment().format('YYYY-MM-DD'),
    });

    // log.info(
    //   `This Month Assigned Amount [${thisMonthAssignedAmount}], Today Assigned Amount [${todayAssignedAmount}]`
    // );

    const currentStockValue = await kitchenInventoryDB.getCurrentStockValueByClientId({
      clientId,
    });


    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Inventory Items Listed Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen stock listed successfully",
      isSuccess: true,
      inventoryStocks: inventoryStocks || [],
      lowInventoryStocks: lowInventoryStocks || [],
      noInventoryStocks: noInventoryStocks || [],
      inventoryItems: inventoryItems || [],
      summary: {
        currentStockValue: currentStockValue || 0,
        totalItems: inventoryItems?.length || 0,
        thisMonthPurchase: monthStockPurchaseAmount || 0,
        todayPurchase: todayStockPurchaseAmount || 0,
        thisMonthAssigned: thisMonthAssignedAmount || 0,
        todayAssigned: todayAssignedAmount || 0,
      }
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.ListInventoryStock = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "ListInventoryStock";

  try {
    let { pageNum, categoryFilters, stockFilter, s} = req.query;

    log.info(`[${C}], [${F}], Page Number [${pageNum}], Category Filter [${categoryFilters}], Stock Filter [${stockFilter}], Search [${s}]`);

    if (categoryFilters && typeof categoryFilters === 'string') {
      categoryFilters = categoryFilters.split(',').map(v => v.trim()).filter(Boolean);
    }

    const userType = req.userType;
    const limit = 10;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }
    let inventoryStocks;
    let searchVal :any = s;
    if(s && s == "") {
      searchVal = null;
    }
    inventoryStocks = await kitchenInventoryDB.getInventoryStockByClientId({
      clientId,
      categoryFilters,
      stockFilter,
      s: searchVal,
      pageNum,
      limit,
    });
    

    // log.info(`Inventory Stocks [${JSON.stringify(inventoryStocks)}]`);
    
    const inventoryItems = await kitchenInventoryDB.getInventoryItemsByClientIdForDropdown({
      clientId,
    });

    const currentStockValue = await kitchenInventoryDB.getInventoryStockValueByClientId({
      clientId,
    });

    // log.info(`Inventory Items [${JSON.stringify(inventoryItems)}]`);

    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Page Number [${pageNum}], Inventory Items Listed Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen stock listed successfully",
      isSuccess: true,
      inventoryStocks: inventoryStocks || [],
      inventoryItems: inventoryItems || [],
      currentStockValue: currentStockValue || 0,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.ListInventoryDistribution = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "ListInventoryDistribution";

  try {
    let { pageNum, categoryFilters, kitchenFilters, startDate, endDate, s } = req.query;

    log.info(`[${C}], [${F}], Page Number [${pageNum}], Category Filter [${categoryFilters}], Kitchen Filter [${kitchenFilters}], Start Date [${startDate}], End Date [${endDate}], Search Val [${s}]`);

    if (categoryFilters && typeof categoryFilters === 'string') {
      categoryFilters = categoryFilters.split(',').map(v => v.trim()).filter(Boolean);
    }

    if (kitchenFilters && typeof kitchenFilters === 'string') {
      kitchenFilters = kitchenFilters.split(',').map(v => v.trim()).filter(Boolean);
    }

    const userType = req.userType;
    const limit = 10;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    let inventoryDistributions = await kitchenInventoryDB.getInventoryDistributionByClientId({
      clientId,
      categoryFilters: categoryFilters ? categoryFilters : null,
      kitchenFilters: kitchenFilters ? kitchenFilters : null,
      searchVal: s,
      startDate,
      endDate,
      pageNum,
      limit,
    });

    if (inventoryDistributions && inventoryDistributions.length > 0) {
      const groupedMap = inventoryDistributions.reduce((acc: any, currentItem: any) => {
        const transferId = currentItem?.transferId || currentItem.id;

        if (!acc[transferId]) {
          acc[transferId] = {
            transferId: transferId,
            totalAmount: 0,
            assignedToId: currentItem.assignedTo,
            kitchenName: currentItem.kitchenName,
            transferDate: currentItem.createdAt,
            entries: [],
          };
        }

        acc[transferId].entries.push(currentItem);
        acc[transferId].totalAmount += Number(currentItem.assignedPrice || 0);

        return acc;
      }, {});

      // Converting the map object into an array of values
      inventoryDistributions = Object.values(groupedMap);
      inventoryDistributions.sort(
        (a: any, b: any) =>
          new Date(b.transferDate).getTime() -
          new Date(a.transferDate).getTime()
      );
    }

    let kitchens = await kitchenInventoryDB.getKitchensByClientIdForDropdown({
      clientId,
    });

    let inventoryStocks = await kitchenInventoryDB.getInventoryStockByClientId({
      clientId,
      categoryFilters:null,
      stockFilter:null,
      pageNum: null,
      limit: null,
    });

    // log.info(`Kitchen [${JSON.stringify(kitchens)}]`);
    // log.info(`Inventory Items Distributions [${JSON.stringify(inventoryDistributions)}]`);
    // log.info(`Inventory Stocks [${JSON.stringify(inventoryStocks)}]`);

    //For web
    let transferSummary = await kitchenInventoryDB.getTransferSummaryByClientId({
      clientId,
      startDate,
      endDate,
    });

    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Page Number [${pageNum}], Inventory Items Listed Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen item distributions listed successfully",
      isSuccess: true,
      inventoryDistributions: inventoryDistributions || [],
      kitchens: kitchens || [],
      inventoryStocks: inventoryStocks || [],
      transferSummary,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.ListPurchaseLedger = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "ListPurchaseLedger";

  try {
    let { s, pageNum, categoryFilters, startDate, endDate } = req.query;

    log.info(`[${C}], [${F}], Page Number [${pageNum}], Category Filter [${categoryFilters}], Start Date [${startDate}], End Date [${endDate}], Search Val [${s}]`);

    if (categoryFilters && typeof categoryFilters === 'string') {
      categoryFilters = categoryFilters.split(',').map(v => v.trim()).filter(Boolean);
    }

    const userType = req.userType;
    const limit = 10;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    let purchaseLedger = await kitchenInventoryDB.getPurchaseLedgerByClientId({
      clientId,
      // categoryFilters: categoryFilters ? categoryFilters : null,
      searchVal: s,
      startDate,
      endDate,
      pageNum,
      limit,
    });
    //log.info(`Purchase Ledger [${JSON.stringify(purchaseLedger)}]`);
    if (purchaseLedger && purchaseLedger.length > 0) {
      const groupedMap = purchaseLedger.reduce((acc: any, currentItem: any) => {
        const invoiceNo = currentItem?.invoiceNo || `INV${currentItem.id}`;

        if (!acc[invoiceNo]) {
          acc[invoiceNo] = {
            invoiceNo: invoiceNo,
            totalAmount: 0,
            vendorId: currentItem.vendorId,
            vendorName: currentItem.vendorName,
            purchaseDate: currentItem.purchaseDate,
            description: currentItem.description,
            invoice: currentItem.invoice || null,
            entries: [],
          };
        }

        acc[invoiceNo].entries.push(currentItem);
        acc[invoiceNo].totalAmount += Number(currentItem.price || 0);

        return acc;
      }, {});

      // Converting the map object into an array of values
      purchaseLedger = Object.values(groupedMap);
    }

    //For Web
    const inventoryItems = await kitchenInventoryDB.getInventoryItemsByClientIdForDropdown({
      clientId,
    });

    const purchaseSummary = await kitchenInventoryDB.getPurchaseSummaryByClientId({
      clientId,
      startDate,
      endDate,
    });

    //log.info(`Purchase Ledger [${JSON.stringify(purchaseLedger)}]`);

    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Page Number [${pageNum}], Inventory Items Listed Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen inventory purchase ledger fetched successfully",
      isSuccess: true,
      inventoryPurchaseLedger: purchaseLedger || [],
      inventoryItems: inventoryItems || [],
      purchaseSummary,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.AddKitchen = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "AddKitchen";

  try {
    let { propIds, name } = req.body;

    log.info(`[${C}], [${F}], Prop Ids [${propIds}], Type of Prop Ids [${typeof propIds}], Name [${name}]`);

    const userType = req.userType;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    const kitchen = await kitchenInventoryDB.getKitchenByName({
      clientId,
      name,
    });

    if(kitchen) {
      log.info(`[${C}], [${F}], Client Id [${clientId}], Kitchen with name already exist`);
      return res.status(400).json({
        msg: `Kitchen name already exists.`,
        isSuccess: false,
      });
    }
    const kitchenId = await kitchenInventoryDB.addKitchen({
      clientId,
      name,
    });

    for (const propId of propIds) {
      await kitchenInventoryDB.linkKitchen({ 
        kitchenId, 
        propId 
      });
    }

    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Prop Id [${propIds}], Name [${name}], Kitchen Id [${kitchenId}], Kitchen Added Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchen Added Successfully",
      isSuccess: true,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.ListKitchen = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "ListKitchen";

  try {
    let { s, propIds, pageNum } = req.query;

    const limit = 10;

    log.info(`[${C}], [${F}], Search Value [${s}], Prop Ids [${propIds}], Page Number [${pageNum}], Limit [${limit}]`);

    if (propIds && typeof propIds === 'string') {
      propIds = propIds.split(',').map(v => v.trim()).filter(Boolean);
    }

    const userType = req.userType;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    let kitchens = await kitchenInventoryDB.getKitchensByClientId({
      clientId,
      searchVal: String(s) && String(s).trim() !== '' && String(s).trim().toLowerCase() !== 'undefined' && String(s).trim().toLowerCase() !== 'null' ? s : null,
      propIds: propIds ? propIds : null,
      pageNum,
      limit,
    });

    if (kitchens && kitchens.length > 0) {
      for (let kitchen of kitchens) {
        const thisMonthAssignedPrice = await kitchenInventoryDB.getAssignedPriceByKitchenIdAndDateRange({
          clientId,
          kitchenId: kitchen.id,
          startDate: moment().startOf('month').format('YYYY-MM-DD'),
          endDate: moment().endOf('month').format('YYYY-MM-DD'),
        });

        kitchen.thisMonthAssignedPrice = thisMonthAssignedPrice || 0;

        const totalAssignedPrice = await kitchenInventoryDB.getAssignedPriceByKitchenId({
          clientId,
          kitchenId: kitchen.id,
        });

        kitchen.totalAssignedPrice = totalAssignedPrice || 0;

        // get property Ids 
        const linkedProps = await kitchenInventoryDB.getLinkedPropertiesByKitchenId({
          kitchenId: kitchen.id,
        });
        
        kitchen.linkedProperties = linkedProps;
      }
    }

    // log.info(`Kitchens [${JSON.stringify(kitchens)}]`);
    
    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Kitchens List Sent Successfully`,
    );

    return res.status(200).json({
      msg: "Kitchens list fetched successfully",
      isSuccess: true,
      kitchens: kitchens || [],
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.EditKitchen = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "EditKitchen";

  try {
    const { kitchenId, name, propIds, } = req.body;

    log.info(`[${C}], [${F}], Kitchen Id [${kitchenId}], Name [${name}], Prop Ids [${JSON.stringify(propIds)}]`);

    const userType = req.userType;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    const kitchen = await kitchenInventoryDB.getKitchenById({id: kitchenId});
    if (!kitchen) {
      log.info(`[${C}], [${F}], Client Id [${clientId}], Kitchen Id [${kitchenId}], No Kitchen Found With Id`);

      return res.status(400).json({
        msg: "No kitchen found",
        isSuccess: false,
      });
    }

    const kitchenNamecheck = await kitchenInventoryDB.getKitchenByNameForEdit({
      clientId,
      name,
      id:kitchenId
    });

    if(kitchenNamecheck) {
      log.info(`[${C}], [${F}], Client Id [${clientId}], Kitchen with name already exist`);
      return res.status(400).json({
        msg: `Kitchen name already exists.`,
        isSuccess: false,
      });
    }

    await kitchenInventoryDB.editKitchen({
      id: kitchenId,
      name: name,
    });

    await kitchenInventoryDB.unlinkKitchenAll({
      kitchenId,
    });

    for (const propId of propIds) {
      await kitchenInventoryDB.linkKitchen({ 
        kitchenId, 
        propId 
      });
    }

    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Kitchen Id [${kitchenId}] Prop Ids [${JSON.stringify(propIds)}], Name [${name}], Kitchen Record Updated Successfully`
    );

    return res.status(200).json({
      msg: "Kitchen details updated",
      isSuccess: true,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

kitchenInventory.DeleteKitchen = async (req: CustomRequest, res: Response) => {
  const C = "Kitchen Inventory Controller";
  const F = "DeleteKitchen";

  try {
    const { kitchenId } = req.body;

    log.info(`[${C}], [${F}], Kitchen Id [${kitchenId}]`);

    const userType = req.userType;

    let { isPartner, clientId } = await isUserPartner(
      Number(userType),
      Number(req.id),
    );

    if (userType === CONSTANTS.USER_TYPE.CLIENT || isPartner) {
      log.info(
        `[${C}], [${F}], ${
          isPartner
            ? `Partner Id [${req.id}], Partner`
            : `Client Id [${clientId}], Client`
        }, Requesting....`,
      );
    } else {
      const staff = await staffDB.getById({ id: req.id });
      if (!staff) {
        log.info(`[${C}], [${F}], Staff Id [${req.id}], No Staff Found`);
        return res.status(400).json({
          msg: CONSTANTS.MSG.INVALID_REQUEST,
          isSuccess: false,
        });
      }
      log.info(
        `[${C}], [${F}], Client Id [${clientId}], Staff Id [${req.id}], Staff Role [${staff.role}], Staff Requesting....`,
      );
    }

    const kitchen = await kitchenInventoryDB.getKitchenById({id: kitchenId});
    if (!kitchen) {
      log.info(`[${C}], [${F}], Client Id [${clientId}], Kitchen Id [${kitchenId}], No Kitchen Found With Id`);

      return res.status(400).json({
        msg: "No kitchen found",
        isSuccess: false,
      });
    }

    await kitchenInventoryDB.updateKitchenStatus({
      id: kitchenId,
      status: CONSTANTS.KITCHEN_STATUS.DELETED,
    });

    log.info(
      `[${C}], [${F}], Client Id [${clientId}], Kitchen Id [${kitchenId}], Kitchen Delete Successfully`
    );

    return res.status(200).json({
      msg: "Kitchen deleted",
      isSuccess: true,
    });
  } catch (error: any) {
    log.info(`[${C}], [${F}], Error: ${error?.message || error}`);
    return res.status(500).json({
      msg: CONSTANTS.MSG.ERROR_MESSAGE,
      isSuccess: false,
    });
  }
};

export default kitchenInventory;
