"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _AuthService = _interopRequireDefault(require("../services/AuthService"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * 
 * @param {import("fastify").FastifyInstance} fastifyInstance 
 * @param {import("fastify").FastifyPluginOptions} options 
 */
const authRouter = async (fastifyInstance, options) => {
  fastifyInstance.post('/', (request, reply) => {
    const {
      password
    } = request.body || {};

    try {
      let token = _AuthService.default.getInstance().signIn(password);

      return reply.status(200).send({
        message: 'OK',
        data: {
          token
        }
      });
    } catch (error) {
      return reply.status(401).send({
        message: 'FAIL',
        cause: error.message
      });
    }
  });
};

var _default = authRouter;
exports.default = _default;