
declare @Roles table (
	[Name] [nvarchar](256) NOT NULL,
	[Description] [nvarchar](256) NULL,
	[IsAllActions] [bit] NULL,
	[CreatedDate] [datetime] NOT NULL,
	[VendorId] [int] NULL,
	[UnitOrganizationId] [int] NULL,
	[guid] [uniqueidentifier] NULL,
	[BackwardCompatibility] [int] NULL)

insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Subscriber',			'The persona which being monitored and uses the service.',getutcdate(),                              '31EBDBC3-8596-4448-A063-1D462772118A',3)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Warehouse technician',	'The persona which prepare the devices in a basic level.',getutcdate(),                              'F1C4B065-85CF-46C3-B262-E4FE26D9BA58',1)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Technician',			'The persona which responsible for the devices maintanance locally and remotly', getutcdate(),      'A508E668-94BC-4076-A8EE-972ADAD06E64',1)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Support',				'The persona which performs the monitoring and facilitiate all the subscriber services',getutcdate(),'14665214-632A-4729-B22B-892CC31B1894',1)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Admin',					'The persona which can modify only unit name, language and timezone for itself',getutcdate(),        '62FD0F19-43D8-4F1E-B7C7-57A8D17A0131',1)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Organization Admin',	'The personna which responsible for the entire customer platform',getutcdate(),                      '1BF4E983-EC11-4A4C-B02B-8F2F7631DAA9',1)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('System admin',			'Ghost, all other roles cant see the System admin. ',getutcdate(),                                  '0E9CB844-06B6-4AEA-A0DC-0FC17EE71BE2',1)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Caregiver',				'The persona which performs a general care monitoring service on the subscriber ',getutcdate(),      'D0275602-E7DF-420F-9E29-77AF67A7B844',2)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Health proffesional',	'The persona which performs a clinical related RPM ',getutcdate(),                                   'B7B24D8B-3ACE-4B6B-8581-6ABD4375470A',2)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Physician',				'The persona which holds the RPMs clinical authority',getutcdate(),                                 'D4F9CE6E-C39F-4179-B2FB-A02F2E4C86B6',2)
insert into @Roles (name,Description,CreatedDate,guid,BackwardCompatibility) values('Medical admin',			'The persona which manages the physicians team',getutcdate(),                                        'A6B2BFC3-D2E0-4496-81D0-224F77085DA5',2)


MERGE INTO [dbo].Roles AS TARGET
USING @Roles AS SOURCE
	ON TARGET.guid = SOURCE.guid
	WHEN MATCHED THEN    
			UPDATE SET name=source.name,
					    Description = source.Description,
						CreatedDate = source.CreatedDate,
						UpdatedDate =  source.CreatedDate,
						guid = source.guid,
						BackwardCompatibility = source.BackwardCompatibility	
	WHEN NOT MATCHED BY TARGET THEN   
			INSERT ( name,Description,CreatedDate,UpdatedDate,guid,BackwardCompatibility) VALUES (Source.name,source.Description,source.CreatedDate,source.CreatedDate, SOURCE.guid,source.BackwardCompatibility)  
OUTPUT $action, SOURCE.*;
