import { FastifyInstanceType } from "../../utils/types";
import {
  login,
  signUp,
  sendCode,
  validateCode,
  updatePassword,
} from "./controller";
import {
  codeSchema,
  emailSchema,
  loginResponseSchema,
  loginSchema,
  passwordResetSchema,
  signupSchema,
} from "./schema";

export async function authRoutes(fastify: FastifyInstanceType) {
  fastify.post(
    "auth/signup/",
    {
      schema: {
        body: signupSchema,
      },
    },
    signUp
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "auth/login/",
    {
      schema: {
        body: loginSchema,
        response: {
          201: loginResponseSchema,
        },
      },
    },
    login
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "password-reset/send-code/",
    {
      schema: {
        body: emailSchema,
      },
    },
    sendCode
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "password-reset/validate-code/",
    {
      schema: {
        body: codeSchema,
      },
    },
    validateCode
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "password-reset/update-password/",
    {
      schema: {
        body: passwordResetSchema,
      },
    },
    updatePassword
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("auth routes registered");
}
