text: const express = require('express');
  const validate = require('express-validation');
  const controller = require('../../controllers/auth.controller');
  const {
    login,
    register,
    refresh,
    sendPasswordReset,
    passwordReset,
    logout,
  } = require('../../validations/auth.validation');
  
  const router = express.Router();
  
  /**
   * @api {post} v1/auth/register Register
   * @apiDescription Register a new user
   * @apiVersion 1.0.0
   * @apiName Register
   * @apiGroup Auth
   * @apiPermission public
   *
   * @apiParam  {String}          email     User's email
   * @apiParam  {String{6..128}}  password  User's password
   * @apiParam  {String{6..128}}  fullName  User's full name
   * @apiParam  {String{6..128}}  name      Organization's name unique
   * @apiParam  {Number}  lat       Organization's latitude
   * @apiParam  {Number}  lng       Organization's longitude
   * @apiParam  {Number}  zipCode   Organization's zip code
   * @apiParam  {String{6..128}}  city      Organization's city
   * @apiParam  {String{6..128}}  country   Organization's country
   *
   * @apiSuccess (Created 201) {String}  token.tokenType     Access Token's type
   * @apiSuccess (Created 201) {String}  token.accessToken   Authorization Token
   * @apiSuccess (Created 201) {String}  token.refreshToken  Token to get a new accessToken
   *                                                   after expiration time
   * @apiSuccess (Created 201) {Number}  token.expiresIn     Access Token's expiration time
   *                                                   in milliseconds
   * @apiSuccess (Created 201) {String}  token.timezone      The server's Timezone
   *
   * @apiSuccess (Created 201) {String}  user.id         User's id
   * @apiSuccess (Created 201) {String}  user.name       User's name
   * @apiSuccess (Created 201) {String}  user.email      User's email
   * @apiSuccess (Created 201) {String}  user.role       User's role
   * @apiSuccess (Created 201) {Date}    user.createdAt  Timestamp
   *
   * @apiError (Bad Request 400)  ValidationError  Some parameters may contain invalid values
   */
  router.route('/register').post(validate(register), controller.register);
  
  /**
   * @api {post} v1/auth/login Login
   * @apiDescription Get an accessToken
   * @apiVersion 1.0.0
   * @apiName Login
   * @apiGroup Auth
   * @apiPermission public
   *
   * @apiParam  {String}         email     User's email
   * @apiParam  {String{..128}}  password  User's password
   *
   * @apiSuccess  {String}  token.tokenType     Access Token's type
   * @apiSuccess  {String}  token.accessToken   Authorization Token
   * @apiSuccess  {String}  token.refreshToken  Token to get a new accessToken
   *                                                   after expiration time
   * @apiSuccess  {Number}  token.expiresIn     Access Token's expiration time
   *                                                   in milliseconds
   *
   * @apiSuccess  {String}  user.id             User's id
   * @apiSuccess  {String}  user.name           User's name
   * @apiSuccess  {String}  user.email          User's email
   * @apiSuccess  {String}  user.role           User's role
   * @apiSuccess  {Date}    user.createdAt      Timestamp
   *
   * @apiError (Bad Request 400)  ValidationError  Some parameters may contain invalid values
   * @apiError (Unauthorized 401)  Unauthorized     Incorrect email or password
   */
  router.route('/login').post(validate(login), controller.login);
  
  /**
   * @api {post} v1/auth/refresh-token Refresh Token
   * @apiDescription Refresh expired accessToken
   * @apiVersion 1.0.0
   * @apiName RefreshToken
   * @apiGroup Auth
   * @apiPermission public
   *
   * @apiParam  {String}  email         User's email
   * @apiParam  {String}  refreshToken  Refresh token aquired when user logged in
   *
   * @apiSuccess {String}  tokenType     Access Token's type
   * @apiSuccess {String}  accessToken   Authorization Token
   * @apiSuccess {String}  refreshToken  Token to get a new accessToken after expiration time
   * @apiSuccess {Number}  expiresIn     Access Token's expiration time in miliseconds
   *
   * @apiError (Bad Request 400)  ValidationError  Some parameters may contain invalid values
   * @apiError (Unauthorized 401)  Unauthorized     Incorrect email or refreshToken
   */
  router.route('/refresh-token').post(validate(refresh), controller.refresh);
  
  /**
   * @api {delete} /v1/auth/logout Logout
   * @apiDescription logout from server
   * @apiVersion 1.0.0
   * @apiName Logout
   * @apiGroup Auth
   * @apiPermission logged user
   *
   * @apiParam  {String}  email         User's email
   * @apiParam  {String}  refreshToken  Refresh token aquired when user logged in
   *
   * @apiSuccess (No Content 204) Successfully  user disconnected
   *
   * @apiError (Bad Request 400)  ValidationError  Some parameters may contain invalid values
   * @apiError (Unauthorized 401)  Unauthorized     Incorrect email or refreshToken
   */
  router.route('/logout').delete(validate(logout), controller.logout);
  
  /**
   * @api {delete} /v1/auth/send-password-reset Send Password Reset
   * @apiDescription send password reset demand to server
   * @apiVersion 1.0.0
   * @apiName Send Password Reset
   * @apiGroup Auth
   *
   * @apiParam  {String}  email         User's email
   *
   * @apiSuccess (No Content 200) Successfully received demand
   *
   * @apiError (Bad Request 400)  ValidationError  Some parameters may contain invalid values
   * @apiError (Unauthorized 401)  Unauthorized     Incorrect email or not found
   */
  router
    .route('/send-password-reset')
    .post(validate(sendPasswordReset), controller.sendPasswordReset);
  
  /**
   * @api {delete} /v1/auth/reset-password Reset Password
   * @apiDescription change old password with new one
   * @apiVersion 1.0.0
   * @apiName Reset Password
   * @apiGroup Auth
   *
   * @apiParam  {String}  email         User's email
   * @apiParam  {String}  password         User's new password
   * @apiParam  {String}  resetToken  Reset token a quired when user received email to reset password
   *
   * @apiSuccess (No Content 200) Successfully Password Updated
   *
   * @apiError (Bad Request 400)  ValidationError  Some parameters may contain invalid values
   * @apiError (Unauthorized 401)  Unauthorized     Incorrect email or resetToken
   */
  router
    .route('/reset-password')
    .post(validate(passwordReset), controller.resetPassword);
  
  module.exports = router;
  