'use strict';
const { createNormalizer } = require('./base-normalizer');
module.exports = createNormalizer('operator_permission', {
  scope: 'tenant',
  canonical: (row) => {
    const permissions = row.source_table === 'usuariosperfilescatalogo'
      ? ['nuevo', 'editar', 'eliminar'].filter((action) => Boolean(row[action])).map((action) => `catalog:${row.catalogo}:${action}`)
      : Object.entries(row)
        .filter(([key, value]) => !['external_id', 'source_table', 'source_id', 'source_updated_at', 'cursor', 'idusuariosperfiles', 'descripcion'].includes(key) && Boolean(value))
        .map(([key]) => key);
    return { role_external_id: row.idusuariosperfiles, permissions: permissions.sort() };
  },
});
