-- Cleanup test data created for Phase 1 validation tests
-- Remove test articles and mappings to leave database clean

-- Remove test mappings
DELETE FROM ARTICOLE_TERTI WHERE sku IN ('CAFE100', '8000070028685', 'TEST001');

-- Remove test articles (using specific ID_ARTICOL range to avoid removing real data)
DELETE FROM NOM_ARTICOLE WHERE ID_ARTICOL BETWEEN 9999001 AND 9999003;

-- Remove any test orders created during testing (optional - to avoid accumulation)
DELETE FROM COMENZI_ELEMENTE WHERE ID_COMANDA IN (
    SELECT ID_COMANDA FROM COMENZI 
    WHERE NR_COMANDA LIKE 'COMPLETE-%' 
       OR NR_COMANDA LIKE 'FINAL-TEST-%'
       OR NR_COMANDA LIKE 'GOMAG-TEST-%'
       OR NR_COMANDA LIKE 'TEST-%'
       OR COMANDA_EXTERNA LIKE '%TEST%'
);

DELETE FROM COMENZI 
WHERE NR_COMANDA LIKE 'COMPLETE-%' 
   OR NR_COMANDA LIKE 'FINAL-TEST-%'
   OR NR_COMANDA LIKE 'GOMAG-TEST-%'
   OR NR_COMANDA LIKE 'TEST-%'
   OR COMANDA_EXTERNA LIKE '%TEST%';

-- Remove test partners created during testing (optional)
DELETE FROM NOM_PARTENERI 
WHERE DENUMIRE LIKE '%Test%' 
  AND ID_UTIL = -3
  AND DATAORA > SYSDATE - 1; -- Only today's test partners

COMMIT;

PROMPT === Test Data Cleanup Complete ===