'use strict';
var express = require('express');
var route = require('./index');
var router = express.Router();
var User = require('../models/user');

/**
 * @api {get} /users/:id Get user(s)
 * @apiName GetUsers
 * @apiGroup User
 *
 * @apiParam {String} [id] User unique ID
 *
 * @apiPermission access
 * @apiUse UserSuccess
 * @apiUse UserSuccessResponse
 */
router.get('/:id?', (req, res) => route.getCollection(req, res, User));

/**
 * @api {get} /users/my/profile Get current user's profile
 * @apiName GetUserProfile
 * @apiGroup User
 *
 * @apiPermission access
 * @apiUse UserSuccess
 * @apiUse UserSuccessResponse
 */
router.get('/my/profile', (req, res) => {
  route.getCollection(req, res, User, {
    username: req.session.user.username
  });
});

module.exports = router;

/**
 * @apiDefine UserSuccess
 *
 * @apiSuccess {String} _id
 * @apiSuccess {String} username
 * @apiSuccess {String} firstName
 * @apiSuccess {String} lastName
 * @apiSuccess {String} email
 * @apiSuccess {String} role <b>values</b>: user, admin
 * @apiSuccess {String[]} groups Array of Group IDs
 */

/**
 * @apiDefine UserSuccessResponse
 *
 * @apiSuccessExample {json} Success-Response:
 *      [{
 *          "_id": "561ce8ac0f277e8b763929ac",
 *          "username": "admin",
 *          "firstName": "Tony",
 *          "lastName": "Stark",
 *          "email": "tony.stark@gmail.com",
 *          "role": "user",
 *          "groups": ["561e1b237f4e1714ffd52b1e"]
 *      }]
 */
