SET QUOTED_IDENTIFIER ON;

GO

EXEC SEC.UpsertProcedureAndSetToProfile 'Ladle.GetTapTempAlertConfiguration', 'admin Profile', 'devops'
EXEC SEC.UpsertProcedureAndSetToProfile 'Ladle.GetTapTempAlertConfiguration', 'Supervisor Profile', 'devops'

EXEC SEC.UpsertProcedureAndSetToProfile 'Ladle.UpdateTapTempAlertConfiguration', 'admin Profile', 'devops'
EXEC SEC.UpsertProcedureAndSetToProfile 'Ladle.UpdateTapTempAlertConfiguration', 'Supervisor Profile', 'devops'


IF NOT EXISTS (SELECT 1 FROM REF.RootState WHERE RootStateId = 303)
    INSERT INTO REF.RootState (RootStateId, RootStateName, RootTypeId) VALUES (303, 'OOS - Returned - Maintenance', 3);
GO

UPDATE REF.RootState SET RootStateName = 'In Service'                   WHERE RootStateId = 302 AND RootStateName <> 'In Service';
UPDATE REF.RootState SET RootStateName = 'OOS - At Vendor'              WHERE RootStateId = 301 AND RootStateName <> 'OOS - At Vendor';
UPDATE REF.RootState SET RootStateName = 'OOS - Returned - Maintenance' WHERE RootStateId = 303 AND RootStateName <> 'OOS - Returned - Maintenance';
GO


IF NOT EXISTS (SELECT 1 FROM REF.LocationType WHERE LocationTypeId = 7)
    INSERT INTO REF.LocationType (LocationTypeId, LocationTypeName) VALUES (7, 'Returned From Vendor Queue');
GO

DECLARE @rfvId INT = 335;
WHILE @rfvId <= 340
BEGIN
    IF NOT EXISTS (SELECT 1 FROM REF.Location WHERE LocationId = @rfvId)
        INSERT INTO REF.Location (LocationId, RootTypeId, LocationName, IsActive, LocationTypeId)
        VALUES (@rfvId, 3, CONCAT('Returned From Vendor ', @rfvId - 334), 1, 7);
    SET @rfvId = @rfvId + 1;
END
GO

EXEC SEC.UpsertProcedureAndSetToProfile 'Location.GetAvailableBuildStands', 'admin Profile', 'devops'
EXEC SEC.UpsertProcedureAndSetToProfile 'Location.GetAvailableBuildStands', 'Supervisor Profile', 'devops'

EXEC SEC.UpsertProcedureAndSetToProfile 'Location.GetAvailableBuildStands', 'Operator Profile', 'devops'
GO
