'use strict';

const { createNormalizer } = require('./base-normalizer');

module.exports = createNormalizer('operator_user', {
  scope: 'tenant',
  omit: ['idempresa'],
  canonical: (row) => ({
    external_operator_id: row.usuario || row.idmesero,
    display_name: row.nombre || null,
    source_kind: row.source_table === 'meseros' ? 'waiter' : 'pos_user',
    role_external_id: row.perfil || null,
    active: row.status !== undefined ? Boolean(row.status) : row.visible !== undefined ? Boolean(Number(row.visible)) : true,
    administrator: Boolean(row.administrador),
    password_change_required: row.passexpired !== undefined ? Boolean(row.passexpired) : undefined,
    source_workspace_id: row.WorkspaceId || null,
  }),
});
