#!/usr/bin/env node

const fs = require("fs");
const path = require("path");

const arg = process.argv[2];
const name = arg.trim().toLowerCase();

const content = `
import { NextFunction } from "express";

import { IWorkLenzRequest } from "../../interfaces/worklenz-request";
import { IWorkLenzResponse } from "../../interfaces/worklenz-response";
import { ServerResponse } from "../../models/server-response";

export default function (req: IWorkLenzRequest, res: IWorkLenzResponse, next: NextFunction): IWorkLenzResponse | void {
  const { example_name } = req.body;
  if (!example_name)
    return res.status(200).send(new ServerResponse(false, null, "Name is required"));
  return next();
}
`;

const fullName = `${name}-validator`;
fs.writeFileSync(path.join(__dirname, "../src/middlewares/validators", `${fullName}.ts`), content.trim(), "utf8");

console.log(`${fullName} generated`);
