\pset pager off
\echo '=== 1. Configuración de despliegue ==='
SELECT tenant, site, scope_code, mode, planned_go_live_date, actual_go_live_at,
       review_owner_primary, review_owner_secondary, daily_review_limit
FROM mv_loss_intelligence.deployment_config
WHERE tenant = 'ucepsa' AND site = 'ucepsa_onpremise';

\echo '=== 2. Parámetros económicos ==='
SELECT parameter_code, parameter_value, unit, confidence, includes_energy,
       valid_from, source_ref, approved_by
FROM mv_loss_intelligence.economic_parameters
WHERE tenant = 'ucepsa' AND site = 'ucepsa_onpremise' AND is_active = true
ORDER BY parameter_code, valid_from DESC;

\echo '=== 3. Calidad de dato ==='
SELECT * FROM mv_reports_ucepsa_prod.li_data_quality_v1 ORDER BY check_code;

\echo '=== 4. Intervalos Odoo más recientes ==='
SELECT machine_id, effective_from, effective_to, odoo_state,
       order_present, order_coherent, production_order, product_id, product,
       qty_production
FROM mv_reports_ucepsa_prod.li_order_state_intervals_v1
ORDER BY effective_from DESC
LIMIT 20;

\echo '=== 5. Resumen de elegibilidad en sombra ==='
SELECT *
FROM mv_reports_ucepsa_prod.li_shadow_summary_v1
ORDER BY machine_id, eligibility_status;

\echo '=== 6. Primeros candidatos de sombra ==='
SELECT shadow_rank, machine_id, order_ref, product_name, cause_name,
       event_count, started_at, duration_min, capacity_loss_eur,
       queue_status
FROM mv_reports_ucepsa_prod.li_shadow_review_queue_v1
ORDER BY shadow_rank
LIMIT 20;

\echo '=== 7. Cola oficial: debe estar vacía en SHADOW ==='
SELECT COUNT(*) AS official_operator_queue_rows
FROM mv_reports_ucepsa_prod.li_operator_stop_queue_v1;

\echo '=== 8. Cobertura bolsas/golpe y cadencia ==='
SELECT *
FROM mv_reports_ucepsa_prod.li_product_cycle_coverage_v1
ORDER BY latest_stop_started_at DESC NULLS LAST;

\echo '=== 9. Catálogo de acciones ==='
SELECT action_id, source_cause_code, action_type, action_candidate,
       suggested_owner, test_window, success_criteria
FROM mv_loss_intelligence.action_catalog
WHERE catalog_code = 'LI-CUTTER-STOPS' AND is_active = true
ORDER BY source_cause_code, action_id;
