CREATE PROCEDURE [MIG_SET_AUTOCAD_USER_PREFERENCE_Sp]
( 
	@TargetControlType NVARCHAR(MAX),
	@LegacyPropName NVARCHAR(MAX),
	@LegacyPropGuiType NVARCHAR(MAX),
	@InputPropValue NVARCHAR(MAX),
	@TargetPropValue NVARCHAR(MAX) OUTPUT
)
AS

BEGIN
			-- PROPGUITYPE

			-- 0 - Check-Box
			-- 1 - Dropdown list
			-- 2 - Textbox (directory etc.)
			-- 3 - (plain) Textbox --> to be treated like "Textbox (string mapping)"
			-- 4 - Mapping Rules (Template-ID) --> to be treated like "Textbox (string mapping)"
			-- 5 - Pane/Workarea --> not supported in "pd"
			-- 6 - Project (Reference) --> to be treated like "Textbox (string mapping)"

			IF @LegacyPropGuiType = '0' AND @TargetControlType = 'Check Box'
				SET @TargetPropValue = 
					CASE 
						WHEN @InputPropValue = '1' THEN 
							'1' --yes
						WHEN @InputPropValue = '0' THEN 
							'2' --no
						ELSE
							'2' --default (no)
					END
			ELSE IF @LegacyPropGuiType = '1' AND @TargetControlType = 'Combo Box' 
				BEGIN
					IF @LegacyPropName = 'CHECK_IN_CLEANUP'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Make Files Read-Only' THEN 
											'10' --readonly.files
									  WHEN @InputPropValue = 'Delete File' THEN 
											'20' --delete.files
									  ELSE 
											'20' --default (delete.files)
									END
					  END

					ELSE IF @LegacyPropName = 'SAVE_AND_UNLOCK_CLEANUP'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Make Files Read-Only' THEN 
											'10' --readonly.files
									  WHEN @InputPropValue = 'Delete File' THEN 
											'20' --delete.files
									  ELSE 
											'20' --default (delete.files)
									END
					  END

					ELSE IF @LegacyPropName = 'ACTION_FOR_OBJECTS_LOCKED_BY_BP'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Attached as unlocked' THEN 
											'10' --attach.as.unlok
									  WHEN @InputPropValue = 'Do not attach' THEN 
											'20' --do.not.attach
									  WHEN @InputPropValue = 'Cancel action' THEN 
											'30' --cancel.action
									  WHEN @InputPropValue = 'Always attach as unlocked' THEN 
											'40' --always.unlocked
									  ELSE 
											'30' --cancel.action
									END
					  END

					ELSE IF @LegacyPropName = 'ATTACHED_TO_BP'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Documents Only' THEN 
											'10' --documents.only
									  WHEN @InputPropValue = 'Items Only' THEN 
											'20' --items.only
									  WHEN @InputPropValue = 'Both' THEN 
											'30' --both
									  ELSE 
											'10' --default (no)
									END
					  END

					ELSE IF @LegacyPropName = 'UNIQUE_FILE_NAMES'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Unique across all projects' THEN 
											'10' -- uniq.all.proj
									  WHEN @InputPropValue = 'Unique per project' THEN 
											'20' -- uniq.per.proj 
									  WHEN @InputPropValue = 'Duplicate file name is allowed' THEN
											'30' -- dupl.allowed 
									  ELSE 
											'20' -- default(uniq.per.proj )
									END
					  END

					ELSE IF @LegacyPropName = 'NEUTRAL_FILES_GENERATION'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'On All Actions' THEN 
											'10' --all.actions
									  WHEN @InputPropValue = 'On Save and Unlock' THEN 
											'10' --save.unlock
									  WHEN @InputPropValue = 'On Check-In' THEN 
											'30' --check.in
									  WHEN @InputPropValue = 'On Save and Unlock and Check-In' THEN
											'40' --save.unlk.chkin
									  ELSE 
											'10' -- default(all.actions)
									END
					  END

					ELSE IF @LegacyPropName = 'ACTION_TO_TAKE_IF_ITEMID_EXISTS_IN_PLM'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Cancel Save' THEN 
											'10' --cancel.save
									  WHEN @InputPropValue = 'Generate Auto ID' THEN 
											'20' --gen.auto.id
									  WHEN @InputPropValue = 'Link to existing Item (If Item Already used - Cancel)' THEN 
											'30' --lnk.itm.cancel
									  WHEN @InputPropValue = 'Link to existing Item (If Item Already used - Set Defining Manually)' THEN 
											'40' --lnk.itm.manual
									  WHEN @InputPropValue = 'Link to existing Item (If Item Already used - Set Defining to No)' THEN 
											'50' --lnk.itm.no
									  WHEN @InputPropValue = 'Link to existing Item (If Item Already used - Set Defining to Yes)' THEN 
											'60' --lnk.itm.yes
									  ELSE 
											'10' --cancel.save
									END
					  END

					ELSE IF @LegacyPropName = 'DUPLICATE_ITEM_IDS_ACTION'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Cancel Save' THEN 
											'10' --cancel.save
									  WHEN @InputPropValue = 'Generate Auto ID' THEN 
											'20' --gen.auto.id
									  WHEN @InputPropValue = 'Allow Link to existing Item' THEN 
											'30' --link.exit.item
									  ELSE 
											'10' --cancel.save
									END
					  END

					ELSE IF @LegacyPropName = 'INITAL_SETTING_OF_ITEM_ID_TO_MATCH_FILENAME'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'None' THEN 
											'10' --none
									  WHEN @InputPropValue = 'File Name' THEN 
											'20' --file.name
									  WHEN @InputPropValue = 'Part Number' THEN 
											'30' --part.number
									  WHEN @InputPropValue = 'Custom Property [Document Level]' THEN
											'40' --cust.property
									  ELSE 
											'10' --none
									END
					  END

					ELSE IF @LegacyPropName = 'QUERY_SEARCH_DEFAULT'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'File' THEN 
											'10' -- file
									  WHEN @InputPropValue = 'Doc' THEN 
											'20' -- doc 
									  WHEN @InputPropValue = 'Item' THEN 
											'30' -- item 
									  ELSE 
											'10' -- file
									END
					  END

					ELSE IF @LegacyPropName = 'THUMBNAIL_GENERATION_FOR_SUBSTRUCTURE'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'All Levels' THEN 
											'10' -- all.levels
									  WHEN @InputPropValue = 'Selected document only' THEN 
											'20' -- sel.documents
									  WHEN @InputPropValue = 'Prompt' THEN 
											'30' -- prompt
									  ELSE 
											'10' -- default(all.levels)
									END
					  END

					ELSE IF @LegacyPropName = 'THUMBNAIL_TYPE_FOR_GENERATION'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'JPG' THEN 
											'10' -- jpg
									  WHEN @InputPropValue = 'PNG' THEN 
											'20' -- png 
									  ELSE 
											'20' -- default(png)
									END
					  END 

					ELSE IF @LegacyPropName = 'DEFAULT_MAPPING_TEMPLATE_ASSEMBLY_FILES'
					BEGIN
						SET @TargetPropValue = @InputPropValue
					END

					ELSE IF @LegacyPropName = 'DEFAULT_MAPPING_TEMPLATE_DRAWING_FILES'
						BEGIN
							SET @TargetPropValue = @InputPropValue
						END

					ELSE IF @LegacyPropName = 'DEFAULT_MAPPING_TEMPLATE_PART_FILES'
						BEGIN
							SET @TargetPropValue = @InputPropValue
						END

					ELSE IF @LegacyPropName = 'LAYOUTS_FOR_BMP_GENERATION'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Model Space Layout Only' THEN 
											'10' -- model.space
									  WHEN @InputPropValue = 'Active Layout Only' THEN 
											'20' -- active.layout 
									  WHEN @InputPropValue = 'All Layouts' THEN 
											'30' -- all.layouts 
									  ELSE 
											'10' -- model.space
									END
					  END 

					ELSE IF @LegacyPropName = 'LAYOUTS_FOR_PDF_GENERATION'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Model Space Layout Only' THEN 
											'10' -- model.space
									  WHEN @InputPropValue = 'Active Layout Only' THEN 
											'20' -- active.layout 
									  WHEN @InputPropValue = 'All Layouts (Single PDF)' THEN 
											'30' -- all.single.pdf
									  WHEN @InputPropValue = 'All Layouts (Separate PDF)' THEN 
											'40' -- all.sep.pdf  
									  ELSE 
											'10' -- model.space
									END
					  END


					ELSE IF @LegacyPropName = 'SET_FILE_NAME_FOR'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'None' THEN 
											'10' -- none
									  WHEN @InputPropValue = 'Main File' THEN 
											'20' -- main.file 
									  ELSE 
											'10' -- none
									END
					  END
					  
					ELSE IF @LegacyPropName = 'LAYOUT_FOR_THUMBNAIL_GENERATION'
					  BEGIN
						SET @TargetPropValue = CASE
									  WHEN @InputPropValue = 'Model Space Layout' THEN 
											'10' -- model.space
									  WHEN @InputPropValue = 'Active Layout' THEN 
											'20' -- active.layout 
									  ELSE 
											'10' -- model.space
									END
					  END

				END
		
			ELSE
				SET @TargetPropValue = @InputPropValue

END		





