import insertColumns from './registers/insert.columns.js';
import insertFilters from './registers/insert.filters.js';

import metadataXML from './metadata/metadataXML.js';

import getLayerGeom from './services/get.layer.geom.js';
import gisRegistry from './registers/gis.registry.js';
import gisRegistryList from './registers/gis.registry.list.js';
import mapRegistry from './registers/map.registry.js';
import gisExport from './registers/gis.export.js';

import getServices from './services/get.services.js';
import deleteService from './services/del.service.js';
import addService from './services/add.service.js';

import addGisRegistry from './registers/add.registry.js';
import deleteGisRegistry from './registers/del.registry.js';
import getServicesCol from './services/get.services.col.js';
import legendAuto from './services/legend.auto.js';
import mapInfoPoint from './ogc/map.info.point.js';
import getDashboard from './dashboard.js';

import getCartocss from './cartocss/get.cartocss.js';
import addCartocss from './cartocss/add.cartocss.js';

const mapInfoPointSchema = {
  querystring: {
    type: 'object',
    properties: {
      x: { type: 'number' },
      y: { type: 'number' },
      layers: { type: 'string' },
      index: { type: 'number', minimum: 0 },
    },
    required: ['x', 'y', 'layers'],
  },
};

const params = { config: { package: 'gis' } };
const publicParams = { config: { policy: 'L0', package: 'gis' } };

async function route(app) {
  app.put('/insert-columns/:token', params, insertColumns);
  app.put('/insert-filters/:token', params, insertFilters);
  app.get('/gis-registry/:slug', publicParams, gisRegistry);
  app.get('/gis-registry/:slug/:objectId', publicParams, gisRegistry);
  app.get('/gis-registry', publicParams, gisRegistryList);
  app.post('/gis-registry', publicParams, addGisRegistry);
  app.put('/gis-registry/:slug', publicParams, addGisRegistry);
  app.delete('/gis-registry/:slug', publicParams, deleteGisRegistry);
  app.get('/map-registry/:slug/:id', publicParams, mapRegistry);

  app.get('/xml/:id', publicParams, metadataXML);

  app.get('/get-layer-geom/:id', publicParams, getLayerGeom);

  app.get('/gis-export/:type/:slug', publicParams, gisExport);

  app.get('/gis-service/:id?', publicParams, getServices);
  app.get('/gis-service/:id/:col', publicParams, getServicesCol);
  app.post('/gis-service/:id?', publicParams, addService);
  app.put('/gis-service/:id', publicParams, addService);
  app.delete('/gis-service/:id', publicParams, deleteService);
  app.get('/legend-auto/:id', publicParams, legendAuto);

  app.get('/map-info-point', { ...publicParams, schema: mapInfoPointSchema }, mapInfoPoint);

  app.get('/dashboard', publicParams, getDashboard);

  app.get('/cartocss/:id', publicParams, getCartocss);
  app.post('/cartocss/:id', publicParams, addCartocss);
}
export default route;
