import cors from "cors";
import express from "express";
import rateLimit from "express-rate-limit";
import helmet from "helmet";

import { authRouter } from "./routes/auth";
import { inviteRouter } from "./routes/invites";
import { meRouter } from "./routes/me";
import { notificationRouter } from "./routes/notifications";
import { reminderTaskRouter } from "./routes/reminderTasks";
import { todoRouter } from "./routes/todos";
import { userRouter } from "./routes/users";

export const createApp = () => {
  const app = express();
  app.use(helmet());
  app.use(cors());
  app.use(express.json());
  app.use(
    rateLimit({
      windowMs: 60 * 1000,
      max: 120,
      standardHeaders: true,
      legacyHeaders: false,
    })
  );

  app.get("/health", (_req, res) => res.json({ ok: true }));

  app.use("/api/auth", authRouter);
  app.use("/api/invites", inviteRouter);
  app.use("/api/me", meRouter);
  app.use("/api/notifications", notificationRouter);
  app.use("/api/reminder-tasks", reminderTaskRouter);
  app.use("/api/todos", todoRouter);
  app.use("/api/users", userRouter);

  return app;
};
