-- ============================================================================
-- ShopDB Test Data Cleanup Script
-- ============================================================================
-- Run this after test_forms.ps1 to remove test data
-- Replace AUTOTEST_YYYYMMDD_HHMMSS with actual test prefix from test run
-- ============================================================================

-- Set the test prefix (update this with the actual prefix from test output)
SET @test_prefix = 'AUTOTEST_%';

-- Show what will be deleted (preview)
SELECT 'Notifications to delete:' AS info, COUNT(*) AS count FROM notifications WHERE notification LIKE @test_prefix;
SELECT 'Machines to delete:' AS info, COUNT(*) AS count FROM machines WHERE machinenumber LIKE @test_prefix OR alias LIKE @test_prefix;
SELECT 'Printers to delete:' AS info, COUNT(*) AS count FROM printers WHERE printercsfname LIKE @test_prefix;
SELECT 'Subnets to delete:' AS info, COUNT(*) AS count FROM subnets WHERE description LIKE @test_prefix;
SELECT 'Applications to delete:' AS info, COUNT(*) AS count FROM applications WHERE applicationname LIKE @test_prefix;
SELECT 'KB Articles to delete:' AS info, COUNT(*) AS count FROM knowledgebase WHERE shortdescription LIKE @test_prefix;
SELECT 'Vendors to delete:' AS info, COUNT(*) AS count FROM vendors WHERE vendor LIKE @test_prefix;
SELECT 'Models to delete:' AS info, COUNT(*) AS count FROM models WHERE modelnumber LIKE @test_prefix;

-- Uncomment lines below to actually delete (run preview first!)

-- DELETE FROM communications WHERE machineid IN (SELECT machineid FROM machines WHERE machinenumber LIKE @test_prefix OR alias LIKE @test_prefix);
-- DELETE FROM machinerelationships WHERE machineid IN (SELECT machineid FROM machines WHERE machinenumber LIKE @test_prefix OR alias LIKE @test_prefix);
-- DELETE FROM notifications WHERE notification LIKE @test_prefix;
-- DELETE FROM machines WHERE machinenumber LIKE @test_prefix OR alias LIKE @test_prefix;
-- DELETE FROM printers WHERE printercsfname LIKE @test_prefix;
-- DELETE FROM subnets WHERE description LIKE @test_prefix;
-- DELETE FROM applications WHERE applicationname LIKE @test_prefix;
-- DELETE FROM knowledgebase WHERE shortdescription LIKE @test_prefix;
-- DELETE FROM vendors WHERE vendor LIKE @test_prefix;
-- DELETE FROM models WHERE modelnumber LIKE @test_prefix;

-- Verify cleanup
-- SELECT 'Remaining test data:' AS info;
-- SELECT 'Notifications:' AS type, COUNT(*) AS count FROM notifications WHERE notification LIKE 'AUTOTEST%';
-- SELECT 'Machines:' AS type, COUNT(*) AS count FROM machines WHERE machinenumber LIKE 'AUTOTEST%' OR alias LIKE 'AUTOTEST%';
