
DECLARE @SystemParameters TABLE 
		(
			[InstanceName] [nvarchar](50) NOT NULL,
			[InstanceIdentifier] [nvarchar](50) NOT NULL,
			[ParameterKey] [nvarchar](100) NOT NULL,
			[ParameterDesc] [nvarchar](500) NOT NULL,
			[Value] [nvarchar](max) NOT NULL,
			[DataType] [nvarchar](20) NOT NULL,
			[AllowDelete] [bit] NOT NULL
		);

	INSERT @SystemParameters ([InstanceName], [InstanceIdentifier], [ParameterKey], [ParameterDesc], [Value], [DataType], [AllowDelete]) 
	VALUES ('ProvisioningProcess', 'default', 'ProvisioningFinalBatchJson', 'The json for final batch in the provisioning process', 
		'[{"id": "ControlPanel","name": "Control Panel","objectType": "mainTitle","fields": [{"id": "ControlPanel_PanelInfo_title","name": "Panel Info","objectType": "title","fields": [{"id": "ControlPanel_PanelInfo_IsProvisioned","name": "Is Provisioned","objectType": "toggle","value": true}*0*]}]}]', 
		'System.String',0)

	INSERT @SystemParameters ([InstanceName], [InstanceIdentifier], [ParameterKey], [ParameterDesc], [Value], [DataType], [AllowDelete]) 
	VALUES ('ProvisioningProcess', 'default', 'ProvisioningArcAccountJson', 'The json for ArcAccount field for the final batch in provisioning process', 
		',{"id": "ControlPanel_PanelInfo_ARC_AccountNumber","name": "ARC Account Number","objectType": "OpenText","value": "*0*"}', 
		'System.String',0)

	INSERT @SystemParameters ([InstanceName],[InstanceIdentifier],[ParameterKey],[ParameterDesc],[Value],[DataType],[AllowDelete]) 	
	VALUES ('LocalWebApiUrl', 'default', 'ExternalWebApi', 'localhost url for externalwebapi', 'http://localhost/External.API/api/', 'System.String', 0)

	
	MERGE INTO [dbo].[SystemParameters] AS TARGET
	USING @SystemParameters AS SOURCE
	ON		SOURCE.InstanceName = TARGET.InstanceName AND 
			SOURCE.InstanceIdentifier = TARGET.InstanceIdentifier AND 
			SOURCE.ParameterKey = TARGET.ParameterKey
	WHEN NOT MATCHED BY TARGET THEN
		INSERT (InstanceName,InstanceIdentifier,ParameterKey,ParameterDesc,Value,DataType,AllowDelete)
		VALUES (SOURCE.InstanceName,SOURCE.InstanceIdentifier,SOURCE.ParameterKey,SOURCE.ParameterDesc,SOURCE.Value,SOURCE.DataType,SOURCE.AllowDelete)
	WHEN MATCHED THEN
		UPDATE SET  InstanceName = SOURCE.InstanceName,
					InstanceIdentifier =SOURCE.InstanceIdentifier,
					ParameterKey = SOURCE.ParameterKey,
					ParameterDesc = SOURCE.ParameterDesc,
					Value = SOURCE.Value,
					DataType = SOURCE.DataType,
					AllowDelete = SOURCE.AllowDelete
	OUTPUT $ACTION, SOURCE.*;
