<?php
require_once __DIR__ . '/../config/db.php';

try {
    $pdo = getConnection();
    
    // Sample of products that should have been cleaned up (blister and caja deactivated)
    $cleanedSamples = [
        'a0004' => 'Azitromicina de 200mg suspension 30ml',
        'j0008' => 'Jabon Johnson Cremoso 75g ROSADO ORIGINAL sin caja',
        'k0002' => 'Kalizzer suspension de 360ml Antiacio con antifaltulento',
        'a0065' => 'Aciclovir crema topica5% de 10g',
        'w0009' => 'Wingrip Jarabe de 120ml'
    ];
    
    echo "=== VERIFYING CLEANED UP PRODUCTS (Should have BLISTER/CAJA INACTIVE) ===\n";
    foreach ($cleanedSamples as $code => $name) {
        $stmt = $pdo->prepare("SELECT id FROM productos WHERE CodigoInterno = ?");
        $stmt->execute([$code]);
        $pid = $stmt->fetchColumn();
        
        if ($pid) {
            $stmtPres = $pdo->prepare("SELECT presentacion_id, factor_conversion, activo FROM producto_presentaciones WHERE producto_id = ?");
            $stmtPres->execute([$pid]);
            $pres = $stmtPres->fetchAll();
            echo "[$code] $name (ID: $pid):\n";
            foreach ($pres as $p) {
                echo "  - Pres ID: {$p['presentacion_id']} | Factor: {$p['factor_conversion']} | Active: {$p['activo']}\n";
            }
        } else {
            echo "[$code] $name NOT FOUND\n";
        }
    }
    
    // Sample of tablet/capsule products (Should still have active presentations)
    $tabletSamples = [
        'a0011' => 'Atenua 25 mg X 10 Tabletas',
        'a0013' => 'Abdol 50mg x 10 Tabletas',
        'l0127' => 'Loratadina 10mg Gel Caps',
        'n0063' => 'Neuromep capsulas'
    ];
    
    echo "\n=== VERIFYING TABLET/CAPSULE PRODUCTS (Should remain unaffected/active) ===\n";
    foreach ($tabletSamples as $code => $name) {
        $stmt = $pdo->prepare("SELECT id FROM productos WHERE CodigoInterno = ?");
        $stmt->execute([$code]);
        $pid = $stmt->fetchColumn();
        
        if ($pid) {
            $stmtPres = $pdo->prepare("SELECT presentacion_id, factor_conversion, activo FROM producto_presentaciones WHERE producto_id = ?");
            $stmtPres->execute([$pid]);
            $pres = $stmtPres->fetchAll();
            echo "[$code] $name (ID: $pid):\n";
            foreach ($pres as $p) {
                echo "  - Pres ID: {$p['presentacion_id']} | Factor: {$p['factor_conversion']} | Active: {$p['activo']}\n";
            }
        } else {
            echo "[$code] $name NOT FOUND\n";
        }
    }

} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
