const fastify = require("fastify");
const userController = require("../controllers/userController");

module.exports = function (fastify, opts, next) {
  fastify.route({
    method: "POST",
    url: "/api/forTesting/getphoneuser",
    schema: {
      tags: ["ForTesting"],
      description:
        "This is get the user in the system for a given phone number",
      summary:
        "Pass the phone in the format +11234567890 ( us format with the country code )",
      body: {
        type: "object",
        required: ["phone"],
        properties: {
          phone: { type: "string" },
        },
      },
      security: [
        {
          basicAuth: [],
        },
      ],
    },
    //preHandler: fastify.auth([fastify.authenticate]),
    handler: userController.getPhoneUser,
  });

  fastify.route({
    method: "POST",
    url: "/api/forTesting/delphoneuser",
    schema: {
      tags: ["ForTesting"],
      description:
        "This is delete a user in the system for a given phone number",
      summary:
        "Pass the phone in the format +11234567890 ( us format with the country code )",
      body: {
        type: "object",
        required: ["phone"],
        properties: {
          phone: { type: "string" },
        },
      },
      security: [
        {
          basicAuth: [],
        },
      ],
    },
    // Add authentication after testing
    //preHandler: fastify.auth([fastify.authenticate]),
    handler: userController.delPhoneUser,
  });

  // Login for a user is in the main index.js file.
  // fastify-jwt used to create the token was throwing exceptions and requierd
  // it be called before the route is loaded.
  next();
};
