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

const { isAdministratorUser, isLoggedUser } = require('../../middlewares/accessValidator');
const SchemaValidator = require('../../middlewares/schemaValidator');
const PaginateMiddleware = require('../../middlewares/paginate');
const FieldMiddleware = require('../../middlewares/fields');
const notificationController = require('./notification.controller');
const { deviceTokenInputType, notificationSendType } = require('./notification.validations');

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

routes.get('/notifications',
    isAdministratorUser,
    FieldMiddleware.middleware({
        invalidFields: generalInvalidFields
    }),
    PaginateMiddleware.middleware(),
    notificationController.find({
        scopes: ['defaultScope']
    })
);

routes.get('/notifications/:id',
    isAdministratorUser,
    FieldMiddleware.middleware({
        invalidFields: generalInvalidFields
    }),
    notificationController.findOne({
        scopes: ['defaultScope']
    })
);

routes.post('/notifications',
    isAdministratorUser,    
    SchemaValidator(notificationSendType, true), 
    notificationController.sendNotification({
        scopes: ['defaultScope']
    })
);

/* Borrar cuando ya no aparezca la versión 1.0.10 */
routes.post('/notifications/register',
    isLoggedUser,
    SchemaValidator(deviceTokenInputType, true), 
    notificationController.registerDevice()
);

routes.post('/notifications/devices',
    isLoggedUser,
    SchemaValidator(deviceTokenInputType, true),
    notificationController.registerDevice()
);

module.exports = routes;