import { addHook } from '@opengis/fastify-table/utils.js';

// api
import testEmail from './controllers/testEmail.js';
// import readNotifications from './controllers/readNotifications.js'; // mark as read
// import userNotifications from './controllers/userNotifications.js'; // check all, backend pagination

// hook
import onWidgetSet from './hook/onWidgetSet.js'; // send notification on comment

// funcs
// import addNotification from '../notifications/funcs/addNotification.js'; // add to db
// import notification from '../notifications/funcs/sendNotification.js'; // send notification

const emailSchema = {
  type: 'object',
  properties: {
    quertstring: {
      to: { type: 'string', pattern: '^((?!\\.)[\\w\\-_.]*[^.])(@\\w+)(\\.\\w+(\\.\\w+)?[^.\\W])$' },
    },
  },
};

export default async function route(fastify) {

  // fastify.decorate('addNotification', addNotification);
  // fastify.decorate('notification', notification);

  fastify.get('/test-email', { config: { policy: ['user'] }, schema: emailSchema }, testEmail);
  // fastify.get('/notification', { config: { policy: ['user'] }, schema: notificationSchema }, userNotifications); // moved to fastify-table
  // fastify.get('/notification-read/:id?', { config: { policy: ['user'] }, schema: notificationSchema }, readNotifications); // moved to fastify-table
  addHook('onWidgetSet', onWidgetSet);
}
