'use strict';

const { validate } = require('../../validation');

// Validation for main options
const validateOptions = function (serverOpts) {
  validate({ schema, data: serverOpts, reportInfo });

  return serverOpts;
};

const reportInfo = { type: 'options', dataVar: 'options' };

const logFilterSchema = {
  oneOf: [
    { type: 'array', items: { type: 'string' } },
    { type: 'boolean' },
  ],
};

const schema = {
  type: 'object',
  properties: {

    idl: {
      type: 'string',
    },

    opts: {
      type: 'string',
    },

    env: {
      type: 'string',
      enum: ['dev', 'production'],
    },

    logLevel: {
      type: 'string',
      enum: ['info', 'log', 'warn', 'error', 'silent'],
    },

    logFilter: {
      type: 'object',
      properties: {
        payload: logFilterSchema,
        response: logFilterSchema,
        argData: logFilterSchema,
        actionResponses: logFilterSchema,
        headers: logFilterSchema,
        queryVars: logFilterSchema,
        params: logFilterSchema,
        settings: logFilterSchema,
      },
      additionalProperties: false,
    },

    maxDataLength: {
      type: 'integer',
      minimum: 0,
    },

    defaultPageSize: {
      type: 'integer',
      minimum: 0,
    },

    maxPageSize: {
      type: 'integer',
      minimum: {
        $data: '1/defaultPageSize',
      },
    },

    serverName: {
      type: 'string',
    },

    http: {
      type: 'object',
      properties: {
        enabled: {
          type: 'boolean',
        },
        host: {
          type: 'string',
        },
        port: {
          type: 'integer',
          minimum: 0,
          maximum: 65535,
        },
      },
      additionalProperties: false,
    },

  },
  additionalProperties: false,
};

module.exports = {
  validateOptions,
};

@@ -456,91 +456,8 @@
  %7B%0A%0A
-    idl: %7B%0A      type: 'string',%0A    %7D,%0A%0A    opts: %7B%0A      type: 'string',%0A    %7D,%0A%0A
     
@@ -1020,24 +1020,72 @@
 se,%0A    %7D,%0A%0A
+    serverName: %7B%0A      type: 'string',%0A    %7D,%0A%0A
     maxDataL
@@ -1330,56 +1330,8 @@
 %7D,%0A%0A
-    serverName: %7B%0A      type: 'string',%0A    %7D,%0A%0A
     

Rearrange options validation