/*
Configuration Tables
Add configuration for Users policy
*/
--01 - entity type
	DECLARE @ConfigurationEntityTypes TABLE ([Id] [int] NOT NULL,[Title] [nvarchar](max) NOT NULL);

	INSERT into @ConfigurationEntityTypes ([Id], [Title]) VALUES (9, N'UserPolicy');

	SET IDENTITY_INSERT [dbo].[ConfigurationEntityTypes] ON;

		MERGE INTO dbo.[ConfigurationEntityTypes] AS TARGET  
			USING @ConfigurationEntityTypes AS SOURCE  
			ON TARGET.Id = SOURCE.Id	
			WHEN MATCHED THEN    
				UPDATE SET Title = SOURCE.Title
			WHEN NOT MATCHED BY TARGET THEN   
				INSERT ([Id], [Title]) VALUES (SOURCE.Id, SOURCE.Title)  
		OUTPUT $action, SOURCE.*;
		
	SET IDENTITY_INSERT [dbo].[ConfigurationEntityTypes] OFF;

	
--02 - parameter types
	DECLARE @ConfigurationParameterTypes TABLE (Id int NOT NULL,Title nvarchar(max) NOT NULL);

	INSERT into @ConfigurationParameterTypes (Id, Title) VALUES (41, N'MasterCaregiver')
	INSERT into @ConfigurationParameterTypes (Id, Title) VALUES (42, N'StandardCaregiver')


	SET IDENTITY_INSERT dbo.ConfigurationParameterTypes ON

	MERGE INTO dbo.ConfigurationParameterTypes AS TARGET  
		USING @ConfigurationParameterTypes AS SOURCE  
		ON TARGET.Id = SOURCE.Id
		WHEN MATCHED THEN    
			UPDATE SET Title = SOURCE.Title
		WHEN NOT MATCHED BY TARGET THEN   
			INSERT (Id, Title) VALUES (SOURCE.Id, SOURCE.Title)  
	OUTPUT $action, SOURCE.*;

	SET IDENTITY_INSERT dbo.ConfigurationParameterTypes OFF


--03- policy parameters
	DECLARE @ConfigurationEntityParameters TABLE (Id int NOT NULL,EntityId int NOT NULL,ParameterId int not null);

	INSERT into @ConfigurationEntityParameters (Id, EntityId, ParameterId) VALUES (58, 9, 1)	--Name
	INSERT into @ConfigurationEntityParameters (Id, EntityId, ParameterId) VALUES (59, 9, 41)	--MasterCaregiver
	INSERT into @ConfigurationEntityParameters (Id, EntityId, ParameterId) VALUES (60, 9, 42)	--StandardCaregiver

	MERGE INTO dbo.ConfigurationEntityParameters AS TARGET  
		USING @ConfigurationEntityParameters AS SOURCE  
		ON TARGET.Id = SOURCE.Id
		WHEN MATCHED THEN    
			UPDATE SET entityid = SOURCE.entityid,ParameterId=source.ParameterId 
		WHEN NOT MATCHED BY TARGET THEN   
			INSERT (Id, EntityId,ParameterId) VALUES (SOURCE.Id,Source.EntityId, SOURCE.ParameterId)  
	OUTPUT $action, SOURCE.*;

