
DECLARE @CategoryId INT;
DECLARE @MaxMonitoringSettingSortOrder INT;

SELECT	@CategoryId  = id
FROM	SettingCategories
WHERE	Name LIKE 'System';


IF ((SELECT COUNT (1) FROM [dbo].[SystemSettings] WHERE [Name] = 'SSASharedKey') = 0)
BEGIN
	INSERT INTO [dbo].[SystemSettings] ([Name],[Value],[DataType],[Description],[SortOrder],[CategoryId],[Range])
	VALUES ('SSASharedKey', 'aes|||UY+vuorrQyvmcYxXOEGKBodrWwJ0BHDNvWKZpggKo3lrvq+X2FpytMfKZgLNBpVtqhJ/3PgU62wCiovD20MKYtgpwRL0bApZYPs0dokudI8=','Text', NULL, 0, @CategoryId , NULL)
END

UPDATE [dbo].[OAuthIdentifier] SET [DisplayName] = 'ACC/BIM 360' WHERE [DisplayName] = 'BIM360/ACC';

IF ((SELECT COUNT (1) FROM [dbo].[Bim360ProjectTypes] WHERE [IsDefault] = 1) = 0)
BEGIN
    INSERT INTO [dbo].[Bim360ProjectTypes]([Name], [DisplayName], [IsDefault])
    VALUES 
    ('Airport', 'Airport', 0),
    ('Assisted_Living_|_Nursing_Home', 'Assisted Living / Nursing Home', 0),
    ('Bridge', 'Bridge', 0),
    ('Canal_|_Waterway', 'Canal / Waterway', 0),
    ('Convention_Center', 'Convention Center', 0),
    ('Court_House', 'Court House', 0),
    ('Dams_|_Flood_Control_|_Reservoirs', 'Dams / Flood Control / Reservoirs', 0),
    ('Data_Center', 'Data Center', 0),
    ('Demonstration_Project', 'Demonstration Project', 1),
    ('Dormitory', 'Dormitory', 0),
    ('Education_Facility', 'Education Facility', 0),
    ('Government_Building', 'Government Building', 0),
    ('Harbor_|_River_Development', 'Harbor / River Development', 0),
    ('Hospital', 'Hospital', 0),
    ('Hotel_|_Motel', 'Hotel / Motel', 0),
    ('Library', 'Library', 0),
    ('Manufacturing_|_Factory', 'Manufacturing / Factory', 0),
    ('Medical_Laboratory', 'Medical Laboratory', 0),
    ('Medical_Office', 'Medical Office', 0),
    ('Military_Facility', 'Military Facility', 0),
    ('Mining_Facility', 'Mining Facility', 0),
    ('Multi-Family_Housing', 'Multi-Family Housing', 0),
    ('Museum', 'Museum', 0),
    ('Office', 'Office', 0),
    ('Oil_and_Gas', 'Oil & Gas', 0),
    ('OutPatient_Surgery_Center', 'OutPatient Surgery Center', 0),
    ('Parking_Structure_|_Garage', 'Parking Structure / Garage', 0),
    ('Performing_Arts', 'Performing Arts', 0),
    ('Plant', 'Plant', 0),
    ('Power_Plant', 'Power Plant', 0),
    ('Prison_|_Correctional_Facility', 'Prison / Correctional Facility', 0),
    ('Rail', 'Rail', 0),
    ('Recreation_Building', 'Recreation Building', 0),
    ('Religious_Building', 'Religious Building', 0),
    ('Research_Facility_|_Laboratory', 'Research Facility / Laboratory', 0),
    ('Restaurant', 'Restaurant', 0),
    ('Retail', 'Retail', 0),
    ('Seaport', 'Seaport', 0),
    ('Single-Family_Housing', 'Single-Family Housing', 0),
    ('Solar_Farm', 'Solar Farm', 0),
    ('Stadium_|_Arena', 'Stadium / Arena', 0),
    ('Streets_|_Roads_|_Highways', 'Streets / Roads / Highways', 0),
    ('Template_Project_and_Training_Project', 'Template Project and Training Project', 0),
    ('Theme_Park', 'Theme Park', 0),
    ('Transportation_Building', 'Transportation Building', 0),
    ('Tunnel', 'Tunnel', 0),
    ('Utilities', 'Utilities', 0),
    ('Warehouse_(non-manufacturing)', 'Warehouse (non-manufacturing)', 0),
    ('Waste_Water_|_Sewers', 'Waste Water / Sewers', 0),
    ('Water_Supply', 'Water Supply', 0),
    ('Wind_Farm', 'Wind Farm', 0)
END

DECLARE @SortOrder INT;
SELECT @CategoryId = [Id] FROM [dbo].[SettingCategories] WITH(NOLOCK) WHERE [Name] = 'General';
SELECT @SortOrder = COUNT(1) FROM [dbo].[SettingCategories] WITH(NOLOCK)

IF ((SELECT COUNT(1) FROM [dbo].[SystemSettings] WHERE [CategoryId] = @CategoryId AND [Name] = 'Add Login Message') = 0)
BEGIN
    INSERT INTO [dbo].[SystemSettings]([Name], [Value], [DataType], [Description], [SortOrder], [CategoryId], [Range])
    VALUES
    ('Add Login Message', '', 'Text', 'The global message for login', @SortOrder + 1, @CategoryId, NULL)
END


DECLARE @ProjectSettingCategoryName NVARCHAR(100);
SET @ProjectSettingCategoryName = 'ImaginitViewer';
IF ((SELECT COUNT(1) FROM [dbo].[ProjectSettingCategory] WHERE [Name] = @ProjectSettingCategoryName) = 0)
BEGIN
    INSERT INTO [dbo].[ProjectSettingCategory]([Name])
    VALUES (@ProjectSettingCategoryName);
END

SET @ProjectSettingCategoryName = 'AutodeskViewer';
IF ((SELECT COUNT(1) FROM [dbo].[ProjectSettingCategory] WHERE [Name] = @ProjectSettingCategoryName) = 0)
BEGIN
    INSERT INTO [dbo].[ProjectSettingCategory]([Name])
    VALUES (@ProjectSettingCategoryName);
END

DECLARE @SysteCategory INT;
DECLARE @NewSettingName NVARCHAR(40);

SET @NewSettingName = 'Max Days for Weekly Scheduled Tasks'
SET @SysteCategory = (SELECT TOP 1 Id FROM dbo.SettingCategories WHERE [Name] = 'Task Processing');

IF(NOT EXISTS(SELECT * FROM dbo.SystemSettings WHERE CategoryId = @SysteCategory AND [Name] = @NewSettingName))
BEGIN

	INSERT INTO dbo.SystemSettings([Name], [Value], [DataType], [Description], [SortOrder], [CategoryId], [Range])
	VALUES(@NewSettingName, 7, 'Integer', 'Maximum number of scheduled days in weekly tasks', 31, @SysteCategory, '1-7');

END

IF(EXISTS (SELECT * FROM [dbo].[SystemSettings] WHERE [Name] = 'Task Schedule Only On Change Default'))
BEGIN
	UPDATE dbo.SystemSettings SET
	[Range] = 'True,False,Force True',
	[DataType] = 'Text'
	WHERE [Name] = 'Task Schedule Only On Change Default';
END

IF ((SELECT COUNT (1) FROM [dbo].[Notification] WHERE [EntityName] = 'DirectAccPublish' AND [Text] = 'NEW: Publish models directly to ACC') = 0)
BEGIN
	INSERT INTO [dbo].[Notification] ([DaysToNotify], [Text], [EntityName], [EntityTarget])
	VALUES(7, 'NEW: Publish models directly to ACC ', 'DirectAccPublish', 'TaskPlugin')
END

IF ((SELECT COUNT (1) FROM [dbo].[Notification] WHERE [EntityName] = 'AccDocsToPdf' AND [Text] = 'NEW: Convert published ACC files to PDF') = 0)
BEGIN
	INSERT INTO [dbo].[Notification] ([DaysToNotify], [Text], [EntityName], [EntityTarget])
	VALUES(7, 'NEW: Convert published ACC files to PDF ', 'AccDocsToPdf', 'TaskPlugin')
END

UPDATE [dbo].[SystemSettings] SET [Value] = 'False' where [Value] = 'False';
UPDATE [dbo].[SystemSettings] SET [Value] = 'True' where [Value] = 'True';
UPDATE [dbo].[SystemSettings] SET [Range] = 'True,False' where [Range] = 'True,False';