-- Migration: Update users module to use 'emails' instead of 'user_emails'
-- Date: 2025-10-08
-- Description: Changes the Employees module config to use 'emails' field name
--              to match the frontend payload and updated users model

UPDATE modules 
SET config = $json$ {
  "title": "Employee Management",
  "header": [
    {
      "type": "filter-select",
      "options": {
        "source_table": "users",
        "source_column": "user_id",
        "display_column": "full_name",
        "data_column": "full_name",
        "data_column_id": "selected_user_id",
        "placeholder": "Search employees by name...",
        "search_fields": ["full_name"],
        "max_results": 25,
        "debounce_ms": 250,
        "populateMode": "immediate"
      }
    },
    { "type": "button", "label": "Add Employee", "formName": "Employee Account" }
  ],
  "body": [
    {
      "type": "table",
      "options": {
        "tableName": "users",
        "showGlobalSearch": false,
        "addButton": false,
        "filterField": "full_name",
        "listenColumn": "full_name",
        "columnsToShow": ["full_name", "status", "emails", "phones"],
        "arrayFieldViews": {
          "emails": ["email"],
          "phones": ["phone_number"]
        },
        "columnLabels": {
          "emails": "Emails",
          "phones": "Phones"
        }
      }
    }
  ],
  "footer": [
    { "type": "button", "label": "Close", "onClick": "closeModal" }
  ]
} $json$::jsonb
WHERE module_id = '0194a8b2-7777-7123-8123-123456789ac6'::uuid;
