import { OpenAPIHono } from "@hono/zod-openapi";

import comsumeMaterial from "./route/consumeMaterial.js";
import returnMat from "./route/returnMaterial.js";
import createSiloAdjustment from "./route/siloAdjustments/createSiloAdjustment.js";
import postComment from "./route/siloAdjustments/postComment.js";
import getStockSilo from "./route/siloAdjustments/getStockData.js";
import { migrateAdjustments } from "./controller/siloAdjustments/migrateAdjustments.js";
import getSiloAdjustments from "./route/siloAdjustments/getSiloAdjustments.js";
import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js";
import getCycleCountCheck from "./route/getCycleCountChecks.js";
import getPPOO from "./route/getPPOO.js";
import getcyclecount from "./route/getCycleCountLanes.js";
import postBulkOrders from "./route/dm/bulkOrdersIn.js";
import standardTemplate from "./route/dm/getStandardTemplate.js";
import standardForcasttemplate from "./route/dm/getStandardForecastTemplate.js";
import postForecast from "./route/dm/forecastIn.js";
import outbound from "./route/getOutbound.js";
import { runHistoricalData } from "./controller/eom/historicalInv.js";
import intervalChecks from "./route/getActiveLogistics.js";
import getActiveLanes from "./route/getActiveLanes.js";
import removeAsNonReable from "./route/removeAsNonReusable.js";
import getSSCC from "./route/getSSCCNumber.js";
import getConnectionType from "./route/getSiloConnectionData.js";
import detachSilo from "./route/detachSilo.js";
import attachSilo from "./route/attachSilo.js";

const app = new OpenAPIHono();

const routes = [
    comsumeMaterial,
    returnMat,

    // silo
    createSiloAdjustment,
    postComment,
    getStockSilo,
    getSiloAdjustments,
    getConnectionType,
    detachSilo,
    attachSilo,
    //lanes
    getCycleCountCheck,
    //warehouse
    getPPOO,
    getcyclecount,
    getActiveLanes,
    //DM
    postBulkOrders,
    standardTemplate,
    postForecast,
    standardForcasttemplate,
    // outbound deliveries
    outbound,
    intervalChecks,

    // logisitcs
    removeAsNonReable,
    getSSCC,
] as const;

// app.route("/server", modules);
const appRoutes = routes.forEach((route) => {
    app.route("/logistics", route);
});

setTimeout(() => {
    migrateAdjustments();
    runHistoricalData();
}, 120 * 1000); // starts 2 min after a server restart or crash.

/**
 * Start the cycle count check
 */

setTimeout(() => {
    getLanesToCycleCount();
}, 5 * 1000);
setInterval(async () => {
    getLanesToCycleCount();
}, 15 * 60 * 1000);

export default app;
