'use strict';

const Schema = require('paradox-utils').Schema;

module.exports = {

    '/rest-datastore-api': {
        type: 'rest',
        group: '/rest-api',

        description: 'Descripción del api',

        // controller: 'test-rest', // TODO: no es obligatorio
        model: 'datastore.test-model',
    },

    '/rest-mysql-api': {
        type: 'rest',
        group: '/rest-api',

        description: 'Descripción del api',

        // controller: 'test-rest', // TODO: no es obligatorio
        model: 'sql.test-model',
    },

    '/user/:test': {
        controller: 'health',
        action: 'test',

        acl: [
            'user.test'
        ]
    },

    '/image': {
        controller: 'health',
        action: 'image',

        legend: 'internal',

        response: {
            type: [
                'image/*',
            ]
        },

        security: {
            rateLimit: {
                enabled: true,
                freeRetries: 3,
                minWait: 5,
            }
        },

        acl: [
            'image.fetch'
        ]
    },

    '/html': {
        controller: 'health',
        action: 'html',

        base: '',

        response: {
            cache: false,
            headers: {
                'x-api-test': 'value',
                'x-api-test2': (opt) => {
                    return Date.now();
                }
            },
            type: [
                'text/html',
            ]
        }
    },

    '/x-health': {
        type: 'controller',
        controller: 'health',
        action: 'test',
        public: true,

        mock: './api/mock/test.json',

        request: {
            messageOk: {
                source: 'query',
                type: Schema.type.STRING,
                allowNull: true,
            },
            test: {
                type: Schema.type.STRING,
                validate: {
                    isIn: ['test', 'test2', 'test3'],
                },
                allowNull: true,
            },
            conditional: {
                source: 'query',
                type: Schema.type.STRING,
                allowNull: false,
                condition: {
                    test: 'test2',
                }
            }
        }
    },

    '/x-health/:type': {
        type: 'controller',
        controller: 'health',
        action: ':type',
        request: {
            type: {
                type: Schema.type.STRING,
                defaultValue: 'a',

                validate: {
                    isIn: ['a', 'b', 'c']
                }
            },

            address: {
                type: Schema.type.STRING,
                allowNull: false,
                validate: {
                    is: /^https?:\/\//i
                },
                get(v) {
                    return v + ' (HOOK!)';
                },
                example: 'http://example.com/',
            },
            name: {
                type: Schema.type.STRING,
                allowNull: true,
                example: 'test',
            },
            test: {
                group: 'test',

                type: Schema.type.DATE,
            }
        },

        mock: [
            {
                name: 'Respuesta por defecto',
                path: './api/mock/test.json'
            },
            {
                name: 'Otra prueba',
                path: './api/mock/test2.json'
            }
        ]
    }
};