SET QUOTED_IDENTIFIER ON;

GO

-- =============================================
-- Feature: Plant Overview - Horizontal Preheater Commissioning
-- =============================================
-- Changes:
-- 1. Rename HP3/HP4 to HP5/HP6 (locationIds 10, 11)
-- 2. Create new HP3/HP4 entries (locationIds 330, 331)
-- 3. Create LRP1, LRP2, LRP3 entries (locationIds 332, 333, 334)
-- =============================================

-- Rename existing HP3/HP4 to HP5/HP6
UPDATE REF.Location SET LocationName = 'HP5' WHERE LocationId = 10;
UPDATE REF.Location SET LocationName = 'HP6' WHERE LocationId = 11;
GO

-- Create new HP3/HP4 entries
IF NOT EXISTS (SELECT 1 FROM REF.Location WHERE LocationId = 330)
    INSERT INTO REF.Location (LocationId, RootTypeId, LocationName, IsActive, LocationTypeId)
    VALUES (330, 2, 'HP3', 1, 1);
GO

IF NOT EXISTS (SELECT 1 FROM REF.Location WHERE LocationId = 331)
    INSERT INTO REF.Location (LocationId, RootTypeId, LocationName, IsActive, LocationTypeId)
    VALUES (331, 2, 'HP4', 1, 1);
GO

-- Create LRP1, LRP2, LRP3 entries
IF NOT EXISTS (SELECT 1 FROM REF.Location WHERE LocationId = 332)
    INSERT INTO REF.Location (LocationId, RootTypeId, LocationName, IsActive, LocationTypeId)
    VALUES (332, 2, 'LRP1', 1, 1);
GO

IF NOT EXISTS (SELECT 1 FROM REF.Location WHERE LocationId = 333)
    INSERT INTO REF.Location (LocationId, RootTypeId, LocationName, IsActive, LocationTypeId)
    VALUES (333, 2, 'LRP2', 1, 1);
GO

IF NOT EXISTS (SELECT 1 FROM REF.Location WHERE LocationId = 334)
    INSERT INTO REF.Location (LocationId, RootTypeId, LocationName, IsActive, LocationTypeId)
    VALUES (334, 2, 'LRP3', 1, 1);
GO

PRINT 'Plant Overview - Horizontal Preheater Commissioning: Database changes applied successfully.'
GO
