-- Remove Sample Network Infrastructure Devices
-- Date: 2025-11-13
-- Purpose: Delete the test devices created for demonstration

USE shopdb;

-- Remove communications entries for sample devices first (to avoid foreign key issues)
DELETE FROM communications
WHERE machineid IN (
    SELECT machineid FROM machines
    WHERE machinenumber IN (
        'SW-CORE-01', 'SW-DIST-01', 'SW-ACCESS-01', 'SW-ACCESS-02', 'SW-OFFICE-01',
        'SRV-DC-01', 'SRV-SQL-01', 'SRV-FILE-01', 'SRV-WEB-01', 'SRV-BACKUP-01',
        'CAM-ENTRY-01', 'CAM-SHIPPING-01', 'CAM-FLOOR-01', 'CAM-FLOOR-02', 'CAM-OFFICE-01', 'CAM-PARKING-01',
        'AP-OFFICE-01', 'AP-OFFICE-02', 'AP-SHOP-01', 'AP-SHOP-02', 'AP-WAREHOUSE-01',
        'IDF-MAIN', 'IDF-EAST', 'IDF-WEST', 'IDF-SHOP'
    )
);

-- Delete the sample network devices from machines table
DELETE FROM machines
WHERE machinenumber IN (
    -- Switches
    'SW-CORE-01', 'SW-DIST-01', 'SW-ACCESS-01', 'SW-ACCESS-02', 'SW-OFFICE-01',
    -- Servers
    'SRV-DC-01', 'SRV-SQL-01', 'SRV-FILE-01', 'SRV-WEB-01', 'SRV-BACKUP-01',
    -- Cameras
    'CAM-ENTRY-01', 'CAM-SHIPPING-01', 'CAM-FLOOR-01', 'CAM-FLOOR-02', 'CAM-OFFICE-01', 'CAM-PARKING-01',
    -- Access Points
    'AP-OFFICE-01', 'AP-OFFICE-02', 'AP-SHOP-01', 'AP-SHOP-02', 'AP-WAREHOUSE-01',
    -- IDFs
    'IDF-MAIN', 'IDF-EAST', 'IDF-WEST', 'IDF-SHOP'
);

-- Show summary
SELECT 'Sample network devices removed' AS status;

SELECT
    mt.machinetype,
    COUNT(*) AS remaining_count
FROM machines m
INNER JOIN machinetypes mt ON m.machinetypeid = mt.machinetypeid
WHERE mt.machinetypeid IN (16, 17, 18, 19, 20)
AND m.isactive = 1
GROUP BY mt.machinetype
ORDER BY mt.machinetypeid;
