const routes = require('express').Router();

const { cacheSuccesses } = require('../../middlewares/cache');
const { isAdministratorUser, isLoggedUser } = require('../../middlewares/accessValidator');
const SchemaValidator = require('../../middlewares/schemaValidator');

const PaginateMiddleware = require('../../middlewares/paginate');
const FieldMiddleware = require('../../middlewares/fields');
const SortMiddleware = require('../../middlewares/sort');

//const entityValidation = require('./entity.validations');
const valueController = require('./value.controller');

const generalInvalidFields = [
    'createdAt', 'updatedAt',
];


routes.get('/values',
    isLoggedUser,
    cacheSuccesses('24 hours'), 
    FieldMiddleware.middleware({
        invalidFields: generalInvalidFields
    }),
    //PaginateMiddleware.middleware(),
    SortMiddleware.middleware({ default: "name" }), 
    valueController.find()
);

routes.get('/values/:id', 
    isLoggedUser, 
    cacheSuccesses('24 hours'), 
    FieldMiddleware.middleware({
        invalidFields: ['createdAt']
    }),
    valueController.findOne()
);

routes.get('/values/:id/speakers',
    isLoggedUser,
    cacheSuccesses('24 hours'),
    (req, res, next) => {
        req.params.association = 'speakers';
        next();
    },
    valueController.find(),
);


//routes.get('/values/:id/:association',
    //isLoggedUser, 
    /*FieldMiddleware.middleware({
        invalidFields: ['createdAt']
    }),*/
    //PaginateMiddleware.middleware(),
    //SortMiddleware.middleware({ default: "name" }),
    //valueController.find,
//);


module.exports = routes;