From f378d0276851c731143c1054253e267deb7b27a6 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 29 Jul 2026 15:14:04 -0500 Subject: [PATCH] feat(setup): seed completo de companies, endpoints y menus restaurados Co-Authored-By: Claude Sonnet 4.6 --- cron/test_rosablanca.php | 48 ++++- setup/seed_palmas.php | 379 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 423 insertions(+), 4 deletions(-) create mode 100644 setup/seed_palmas.php diff --git a/cron/test_rosablanca.php b/cron/test_rosablanca.php index a82f480..98ae526 100644 --- a/cron/test_rosablanca.php +++ b/cron/test_rosablanca.php @@ -2,7 +2,7 @@ declare(strict_types=1); $BASE = 'https://app.palmas360.com/rosablanca/php/controller/controller_api_externa.php'; -$KEY = '39630f8c4743ac0dba3cecb781bc4c0608ba77f7576f74831d779c42c596e7f0'; +$KEY = 'd8ed3ac2dbe633cd5e0d75cf50503d7be7084a7dbf0ca65325aa54e831491379'; // test key (IP-unrestricted) $TODAY = date('Y-m-d'); $M1 = date('Y-m-01'); @@ -52,10 +52,10 @@ curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>10, $raw = curl_exec($ch); curl_close($ch); $fincas = json_decode($raw, true); $fincaId = 0; -if (!empty($fincas['fincas'])) { - foreach ($fincas['fincas'] as $f) { +if (!empty($fincas['datos'])) { + foreach ($fincas['datos'] as $f) { echo " id={$f['id']} {$f['label']}\n"; - if ($fincaId === 0) $fincaId = (int)$f['id']; + if ($fincaId === 0 && (int)$f['id'] > 0) $fincaId = (int)$f['id']; // skip id=0 (Todas) } } else { echo " " . mb_substr($raw, 0, 200) . "\n"; @@ -92,4 +92,44 @@ hit('cosecha', "{$BASE}?peticion=ciclos_cosecha_dn&fecha_desde={$M1}&finca_i hit('polinizacion',"{$BASE}?peticion=ciclos_polinizacion_dn&fecha_desde={$M1}&finca_id={$fincaId}", $KEY); hit('mantenimiento',"{$BASE}?peticion=mantenimiento_dn&fecha_desde={$M1}&grupo=0&finca_id={$fincaId}", $KEY); +// ── 8. Top texto (lotes con ciclos más largos) ─────────────────────────── +echo "\n── Top texto (sin finca) ──\n"; +hit('cosecha_top', "{$BASE}?peticion=cosecha_top_texto_bot", $KEY); +hit('polinizacion_top', "{$BASE}?peticion=polinizacion_top_texto_bot", $KEY); +hit('censo_top', "{$BASE}?peticion=censo_top_texto_bot", $KEY); +hit('plagas_top', "{$BASE}?peticion=plagas_top_texto_bot", $KEY); +hit('palm_top', "{$BASE}?peticion=palm_top_texto_bot", $KEY); +hit('tratamiento_top', "{$BASE}?peticion=tratamiento_top_texto_bot", $KEY); +hit('mant_top', "{$BASE}?peticion=mantenimiento_top_texto_bot&grupo=0", $KEY); + +if ($fincaId > 0) { + echo "\n── Top texto (con finca_id={$fincaId}) ──\n"; + hit('cosecha_top', "{$BASE}?peticion=cosecha_top_texto_bot&finca_id={$fincaId}", $KEY); + hit('polinizacion_top', "{$BASE}?peticion=polinizacion_top_texto_bot&finca_id={$fincaId}", $KEY); + hit('censo_top', "{$BASE}?peticion=censo_top_texto_bot&finca_id={$fincaId}", $KEY); + hit('plagas_top', "{$BASE}?peticion=plagas_top_texto_bot&finca_id={$fincaId}", $KEY); + hit('palm_top', "{$BASE}?peticion=palm_top_texto_bot&finca_id={$fincaId}", $KEY); + hit('tratamiento_top', "{$BASE}?peticion=tratamiento_top_texto_bot&finca_id={$fincaId}", $KEY); + hit('mant_top', "{$BASE}?peticion=mantenimiento_top_texto_bot&grupo=0&finca_id={$fincaId}", $KEY); +} + +// ── 9. Histórico 30 días (PDF) ──────────────────────────────────────────── +echo "\n── Histórico bot PDF (sin finca) ──\n"; +hit('cosecha_hist', "{$BASE}?peticion=cosecha_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); +hit('polinizacion_hist', "{$BASE}?peticion=polinizacion_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); +hit('censo_hist', "{$BASE}?peticion=censo_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); +hit('plagas_hist', "{$BASE}?peticion=plagas_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); +hit('palm_hist', "{$BASE}?peticion=palm_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); +hit('tratamiento_hist', "{$BASE}?peticion=tratamiento_historico_bot&fecha_hasta={$TODAY}&finca_id=0", $KEY); + +if ($fincaId > 0) { + echo "\n── Histórico bot PDF (con finca_id={$fincaId}) ──\n"; + hit('cosecha_hist', "{$BASE}?peticion=cosecha_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); + hit('polinizacion_hist', "{$BASE}?peticion=polinizacion_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); + hit('censo_hist', "{$BASE}?peticion=censo_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); + hit('plagas_hist', "{$BASE}?peticion=plagas_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); + hit('palm_hist', "{$BASE}?peticion=palm_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); + hit('tratamiento_hist', "{$BASE}?peticion=tratamiento_historico_bot&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY); +} + echo "\n── Fin del test ──\n"; diff --git a/setup/seed_palmas.php b/setup/seed_palmas.php new file mode 100644 index 0000000..99d2609 --- /dev/null +++ b/setup/seed_palmas.php @@ -0,0 +1,379 @@ + '¡Bienvenido a Palmas360! Escribe *menu* para ver las opciones disponibles.', + 'fallback' => 'No entendí. Escribe *menu* para ver las opciones disponibles.', + 'commands' => [ + 'menu' => 'show_main_menu', + 'informes' => 'descargar_informes', + 'info' => 'enviar_informacion', + 'inicio' => 'show_main_menu', + 'volver' => 'show_main_menu', + ], + // ── Menus globales ────────────────────────────────────────────────────── + 'menus' => [ + + // Menú modo trabajo (para per_type=3 tras seleccionar finca) + 'menu_modo_trabajo' => [ + 'type' => 'list', + 'header' => '🌴 Palmas360', + 'body' => '¿Qué deseas hacer?', + 'footer' => 'Palmas360', + 'button' => 'Ver opciones', + 'sections' => [ + [ + 'title' => 'Opciones', + 'rows' => [ + ['id' => 'descargar_informes', 'title' => '📥 Descargar informes', 'description' => 'Ciclos, Producción, Ausentismos'], + ['id' => 'enviar_informacion', 'title' => '📤 Enviar información', 'description' => 'Subir ciclos y datos'], + ], + ], + ], + ], + + // Menú cat2 (descargar informes) — accesible globalmente + 'show_menu_cat2' => [ + 'type' => 'list', + 'header' => '📋 Informes', + 'body' => '¿Qué informe deseas?', + 'footer' => 'Palmas360', + 'button' => 'Ver opciones', + 'sections' => [ + [ + 'title' => 'Informes', + 'rows' => [ + ['id' => 'submenu_produccion', 'title' => '🌿 Producción', 'description' => 'Informes de producción'], + ['id' => 'submenu_ciclos', 'title' => '🔄 Ciclos', 'description' => 'Ciclos de campo'], + ['id' => 'submenu_ausentismos', 'title' => '👥 Ausentismos', 'description' => 'Faltas y novedades'], + ], + ], + ], + ], + + // Submenú producción + 'submenu_produccion' => [ + 'type' => 'list', + 'header' => '🌿 Producción', + 'body' => 'Selecciona el informe:', + 'footer' => 'Palmas360', + 'button' => 'Ver opciones', + 'sections' => [ + [ + 'title' => 'Producción', + 'rows' => [ + ['id' => 'produccion_total', 'title' => '📊 Total del mes', 'description' => 'Resumen y PDF del mes'], + ['id' => 'produccion_lotes', 'title' => '📋 Por lotes (Excel)', 'description' => 'Detalle por lote'], + ], + ], + ], + ], + + // Submenú ciclos + 'submenu_ciclos' => [ + 'type' => 'list', + 'header' => '🔄 Ciclos', + 'body' => 'Selecciona el ciclo:', + 'footer' => 'Palmas360', + 'button' => 'Ver ciclos', + 'sections' => [ + [ + 'title' => 'Ciclos', + 'rows' => [ + ['id' => 'ciclo_cosecha', 'title' => '🌾 Cosecha', 'description' => 'Ciclos de cosecha'], + ['id' => 'ciclo_polinizacion', 'title' => '🌸 Polinización', 'description' => 'Ciclos de polinización'], + ['id' => 'ciclo_censo', 'title' => '📝 Censo', 'description' => 'Ciclos de censo'], + ['id' => 'ciclo_plagas', 'title' => '🐛 Plagas', 'description' => 'Ciclos de plagas'], + ], + ], + [ + 'title' => 'Más ciclos', + 'rows' => [ + ['id' => 'ciclo_palm', 'title' => '🌴 Palm', 'description' => 'Ciclos palm'], + ['id' => 'ciclo_tratamiento', 'title' => '💊 Tratamiento', 'description' => 'Ciclos de tratamiento'], + ['id' => 'ciclo_mantenimiento', 'title' => '🔧 Mantenimiento', 'description' => 'Ciclos de mantenimiento'], + ], + ], + ], + ], + + // Submenú ausentismos + 'submenu_ausentismos' => [ + 'type' => 'list', + 'header' => '👥 Ausentismos', + 'body' => 'Selecciona el período:', + 'footer' => 'Palmas360', + 'button' => 'Ver opciones', + 'sections' => [ + [ + 'title' => 'Período', + 'rows' => [ + ['id' => 'ausentismos_hoy', 'title' => '📅 Hoy', 'description' => '¿Quién faltó hoy?'], + ['id' => 'ausentismos_semana', 'title' => '📆 Esta semana', 'description' => '¿Quién faltó esta semana?'], + ['id' => 'ausentismos_mes', 'title' => '📋 Mes (PDF)', 'description' => 'Reporte mensual PDF'], + ], + ], + ], + ], + + // Submenú subir ciclos (para per_type=3) + 'submenu_subir_ciclos' => [ + 'type' => 'list', + 'header' => '📤 Enviar información', + 'body' => 'Selecciona qué deseas enviar:', + 'footer' => 'Palmas360', + 'button' => 'Ver opciones', + 'sections' => [ + [ + 'title' => 'Opciones', + 'rows' => [ + ['id' => 'subir_ciclo_cosecha', 'title' => '🌾 Ciclo cosecha', 'description' => 'Subir ciclo de cosecha'], + ], + ], + ], + ], + ], + + // ── Flows globales ────────────────────────────────────────────────────── + 'flows' => [ + // Producción + 'produccion_total' => ['type' => 'function', 'function' => 'produccion_total_bot'], + 'produccion_lotes' => ['type' => 'function', 'function' => 'api_report', 'params' => [ + 'endpoint_key' => 'produccion_lotes_bot_dn', + 'filename' => 'produccion_lotes.xlsx', + 'caption' => 'Producción por lotes del año', + ]], + + // Ausentismos + 'ausentismos_hoy' => ['type' => 'function', 'function' => 'ausentismos_bot', 'params' => ['periodo' => 'hoy']], + 'ausentismos_semana' => ['type' => 'function', 'function' => 'ausentismos_bot', 'params' => ['periodo' => 'semana']], + 'ausentismos_mes' => ['type' => 'function', 'function' => 'api_report', 'params' => [ + 'endpoint_key' => 'ausentismos_bot_pdf_dn', + 'filename' => 'ausentismos_mes.pdf', + 'caption' => 'Ausentismos del mes', + ]], + + // Ciclos (menus) + 'submenu_produccion' => ['type' => 'menu', 'menu' => 'submenu_produccion'], + 'submenu_ciclos' => ['type' => 'menu', 'menu' => 'submenu_ciclos'], + 'submenu_ausentismos' => ['type' => 'menu', 'menu' => 'submenu_ausentismos'], + + // Ciclos individuales + 'ciclo_cosecha' => ['type' => 'function', 'function' => 'ciclo_bot', 'params' => ['ciclo' => 'cosecha']], + 'ciclo_polinizacion' => ['type' => 'function', 'function' => 'ciclo_bot', 'params' => ['ciclo' => 'polinizacion']], + 'ciclo_censo' => ['type' => 'function', 'function' => 'ciclo_bot', 'params' => ['ciclo' => 'censo']], + 'ciclo_plagas' => ['type' => 'function', 'function' => 'ciclo_bot', 'params' => ['ciclo' => 'plagas']], + 'ciclo_palm' => ['type' => 'function', 'function' => 'ciclo_bot', 'params' => ['ciclo' => 'palm']], + 'ciclo_tratamiento' => ['type' => 'function', 'function' => 'ciclo_bot', 'params' => ['ciclo' => 'tratamiento']], + 'ciclo_mantenimiento' => ['type' => 'function', 'function' => 'ciclo_bot', 'params' => ['ciclo' => 'mantenimiento']], + + // Upload + 'enviar_informacion' => ['type' => 'menu', 'menu' => 'submenu_subir_ciclos'], + 'subir_ciclo_cosecha' => ['type' => 'function', 'function' => 'upload_ciclo', 'params' => ['ciclo' => 'cosecha']], + + // Placeholders globales + 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], + 'descargar_informes' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], + ], + + // ── Per-type config ───────────────────────────────────────────────────── + 'per_type' => [ + + // Cat 1: solo reporta (envía info, no descarga) + '1' => [ + 'greeting_flow' => 'show_menu_cat1', + 'fallback_flow' => 'show_menu_cat1', + 'greeting' => null, + 'fallback' => null, + 'commands' => ['menu' => 'show_menu_cat1'], + 'menus' => [ + 'show_menu_cat1' => [ + 'type' => 'list', + 'header' => '🌴 Palmas360', + 'body' => '¿Qué deseas hacer?', + 'footer' => 'Palmas360', + 'button' => 'Ver opciones', + 'sections' => [ + [ + 'title' => 'Opciones', + 'rows' => [ + ['id' => 'subir_ciclo_cosecha', 'title' => '🌾 Subir cosecha', 'description' => 'Enviar ciclo de cosecha'], + ], + ], + ], + ], + ], + 'flows' => [ + 'show_menu_cat1' => ['type' => 'menu', 'menu' => 'show_menu_cat1'], + 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat1'], + 'subir_ciclo_cosecha' => ['type' => 'function', 'function' => 'upload_ciclo', 'params' => ['ciclo' => 'cosecha']], + ], + ], + + // Cat 2: solo descarga + '2' => [ + 'greeting_flow' => 'ask_finca', + 'fallback_flow' => 'show_menu_cat2', + 'greeting' => null, + 'fallback' => null, + 'commands' => ['menu' => 'show_menu_cat2'], + 'menus' => [ + 'show_menu_cat2' => [ + 'type' => 'list', + 'header' => '📋 Informes', + 'body' => '¿Qué informe deseas?', + 'footer' => 'Palmas360', + 'button' => 'Ver opciones', + 'sections' => [ + [ + 'title' => 'Informes', + 'rows' => [ + ['id' => 'submenu_produccion', 'title' => '🌿 Producción', 'description' => 'Informes de producción'], + ['id' => 'submenu_ciclos', 'title' => '🔄 Ciclos', 'description' => 'Ciclos de campo'], + ['id' => 'submenu_ausentismos', 'title' => '👥 Ausentismos', 'description' => 'Faltas y novedades'], + ], + ], + ], + ], + ], + 'flows' => [ + 'show_menu_cat2' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], + 'show_main_menu' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], + 'descargar_informes' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], + ], + ], + + // Cat 3: descarga + envío + '3' => [ + 'greeting_flow' => 'ask_finca', + 'fallback_flow' => 'show_main_menu', + 'greeting' => null, + 'fallback' => null, + 'commands' => ['menu' => 'show_main_menu'], + 'menus' => [], + 'flows' => [ + 'show_main_menu' => ['type' => 'menu', 'menu' => 'menu_modo_trabajo'], + 'descargar_informes' => ['type' => 'menu', 'menu' => 'show_menu_cat2'], + 'enviar_informacion' => ['type' => 'menu', 'menu' => 'submenu_subir_ciclos'], + ], + ], + ], +]; + +// ─── Endpoints ───────────────────────────────────────────────────────────────── + +$BASE = 'https://app.palmas360.com/rosablanca/php/controller/controller_api_externa.php'; + +$endpoints = [ + ['key' => 'produccion_total_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=produccion_total_bot&fecha_desde={fecha_desde}&fecha_hasta={fecha_hasta}&finca_id={finca_id}'], + ['key' => 'produccion_total_pdf_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=produccion_total_pdf_bot&fecha_desde={fecha_desde}&fecha_hasta={fecha_hasta}&finca_id={finca_id}'], + ['key' => 'produccion_lotes_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=produccion_lotes_bot&finca_id={finca_id}'], + ['key' => 'ausentismos_bot_texto_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ausentismos_bot_texto&fecha_desde={fecha_desde}&fecha_hasta={fecha_hasta}'], + ['key' => 'ausentismos_bot_pdf_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=ausentismos_bot_pdf&fecha_desde={fecha_desde}&fecha_hasta={fecha_hasta}'], + ['key' => 'cosecha_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=cosecha_top_texto_bot&finca_id={finca_id}'], + ['key' => 'polinizacion_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=polinizacion_top_texto_bot&finca_id={finca_id}'], + ['key' => 'censo_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=censo_top_texto_bot&finca_id={finca_id}'], + ['key' => 'plagas_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=plagas_top_texto_bot&finca_id={finca_id}'], + ['key' => 'palm_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=palm_top_texto_bot&finca_id={finca_id}'], + ['key' => 'tratamiento_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=tratamiento_top_texto_bot&finca_id={finca_id}'], + ['key' => 'mantenimiento_top_texto_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=mantenimiento_top_texto_bot&grupo=0&finca_id={finca_id}'], + ['key' => 'cosecha_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=cosecha_historico_bot&fecha_hasta={fecha_hasta}&finca_id={finca_id}'], + ['key' => 'polinizacion_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=polinizacion_historico_bot&fecha_hasta={fecha_hasta}&finca_id={finca_id}'], + ['key' => 'censo_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=censo_historico_bot&fecha_hasta={fecha_hasta}&finca_id={finca_id}'], + ['key' => 'plagas_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=plagas_historico_bot&fecha_hasta={fecha_hasta}&finca_id={finca_id}'], + ['key' => 'palm_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=palm_historico_bot&fecha_hasta={fecha_hasta}&finca_id={finca_id}'], + ['key' => 'tratamiento_historico_bot_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=tratamiento_historico_bot&fecha_hasta={fecha_hasta}&finca_id={finca_id}'], + ['key' => 'fincas_dn', 'dir' => 'download', 'url' => $BASE . '?peticion=fincas'], +]; + +// ─── Companies ───────────────────────────────────────────────────────────────── + +$companies = [ + [ + 'id' => 2, + 'name' => 'rosablanca', + 'display_name' => 'Rosa Blanca', + 'phone_number_id' => '1168511569675820', + 'display_phone' => '', + 'api_base_url' => 'https://graph.facebook.com/v22.0', + 'api_key' => 'EAAqbNQQekwUBRm8ZAAfCvXZAsxcM1BTkiHjVJYeOfXYCg5t4qYtBL7ap2IdHGa1iXclZBO47gZBshYZBAlQRuUvgSib2Owh7gPnAWfNlHXZAT61ccElXoihuXuEuy0qLiB95tDhLMWPqoKYuDwAHCU78RQxoi1nzz1OsOY40EK7U2tKZBVuZABQZCJctZBrLK7rRiC7AZDZD', + 'bot_type' => 'normal', + 'requires_approval' => 0, + 'is_active' => 1, + ], + [ + 'id' => 3, + 'name' => 'palmas360_test', + 'display_name' => 'Palmas360 Test', + 'phone_number_id' => '1168511569675820', + 'display_phone' => '', + 'api_base_url' => 'https://graph.facebook.com/v22.0', + 'api_key' => 'EAAqbNQQekwUBRm8ZAAfCvXZAsxcM1BTkiHjVJYeOfXYCg5t4qYtBL7ap2IdHGa1iXclZBO47gZBshYZBAlQRuUvgSib2Owh7gPnAWfNlHXZAT61ccElXoihuXuEuy0qLiB95tDhLMWPqoKYuDwAHCU78RQxoi1nzz1OsOY40EK7U2tKZBVuZABQZCJctZBrLK7rRiC7AZDZD', + 'bot_type' => 'normal', + 'requires_approval' => 0, + 'is_active' => 1, + ], +]; + +$configJsonStr = json_encode($configJson, JSON_UNESCAPED_UNICODE); + +// ─── Insert / update companies ──────────────────────────────────────────────── + +$stmtCo = $db->prepare(" + INSERT INTO companies (id, name, display_name, phone_number_id, display_phone, api_base_url, api_key, bot_type, requires_approval, is_active, config_json) + VALUES (:id, :name, :display_name, :phone_number_id, :display_phone, :api_base_url, :api_key, :bot_type, :requires_approval, :is_active, :config_json) + ON DUPLICATE KEY UPDATE + display_name = VALUES(display_name), + phone_number_id = VALUES(phone_number_id), + api_base_url = VALUES(api_base_url), + api_key = VALUES(api_key), + bot_type = VALUES(bot_type), + is_active = VALUES(is_active), + config_json = VALUES(config_json) +"); + +foreach ($companies as $co) { + $stmtCo->execute([ + ':id' => $co['id'], + ':name' => $co['name'], + ':display_name' => $co['display_name'], + ':phone_number_id' => $co['phone_number_id'], + ':display_phone' => $co['display_phone'], + ':api_base_url' => $co['api_base_url'], + ':api_key' => $co['api_key'], + ':bot_type' => $co['bot_type'], + ':requires_approval'=> $co['requires_approval'], + ':is_active' => $co['is_active'], + ':config_json' => $configJsonStr, + ]); + echo "✔ Company {$co['id']} ({$co['display_name']}) OK\n"; +} + +// ─── Insert / update endpoints ──────────────────────────────────────────────── + +$stmtEp = $db->prepare(" + INSERT INTO company_endpoints (company_id, endpoint_key, direction, url) + VALUES (:company_id, :endpoint_key, :direction, :url) + ON DUPLICATE KEY UPDATE url = VALUES(url), direction = VALUES(direction) +"); + +foreach ($companies as $co) { + foreach ($endpoints as $ep) { + $stmtEp->execute([ + ':company_id' => $co['id'], + ':endpoint_key' => $ep['key'], + ':direction' => $ep['dir'], + ':url' => $ep['url'], + ]); + } + echo "✔ " . count($endpoints) . " endpoints OK para company {$co['id']}\n"; +} + +echo "\n✅ Seed completo.\n";