import { Server } from "./server";
import { CronController } from "./controllers/Cron/CronController";
const server: any = require("http").Server(new Server().app);
import socketObj from "./services/SocketService";
import * as cron from "node-cron";

let port = process.env.PORT || 5000;

server.listen(port, () => {
  console.log(`server is listening at port ${port}`);
  socketObj.init(server);
  socketObj.connect();
  console.log("Socket Connected");
});

// Cron Running At Every Minute.
cron.schedule("* * * * *", async function () {
  console.log("Cron Running At Every Minute");

  // Send Notification to Admin
  await CronController.notAcceptAutoAssignBookingByWasher();
  console.log("Cron Running - Not Accept Auto Assigned Booking By Any Washer");

  // Send Notification to Admin when booking not accepted by the washer after admin assigning the washer.
  await CronController.notAcceptAdminAssignBookingByWasher();
  console.log("Cron Running - Not Accept Admin Assigned Booking By The Washer");

});