-------------
-- ROLES (reuse existing casterproducts_read and casterproducts_readWrite)
-------------

-------------------
-- Menu and Route (new pages/ path)
-------------------
	declare @parent int, @result_routeId INT
	select @parent=id from [FrontEnd].[Menu] where [Name] = 'Caster' and Parent is null

	INSERT INTO [FrontEnd].[Routes]
			   ([Route]
			   ,[ModuleName]
			   ,[ModulePath]
			   ,[RequiredRole]
		   )
		 VALUES
			   (
			   '!/caster-products(/:start)(/:end)(/:casterCode)(/:strandId)(/:crewId)(/:shiftId)(/)'
			   , 'caster-products'
			   , 'pages/caster/caster-products/'
			   , 'casterproducts_read'
			   )
			   SET @result_routeId = @@IDENTITY
	INSERT INTO [FrontEnd].[Menu]
			   ([Parent]
			   ,[Name]
			   ,[RouteID]
			   ,[SortOrder]
			   ,[Enabled]
			   ,[Visible]
			   ,[RequiredRole]
			   ,[Group]
			  )
		 VALUES
			   (
			   @parent
			   ,'Products'
			   ,@result_routeId
			   ,1
			   ,1
			   ,1
			   ,'casterproducts_read'
			   ,NULL
			 )
	GO


-------------------
-- SP Permissions
-------------------
EXECUTE sys.sp_addextendedproperty
@level0type = N'USER'
,@level0name = [casterproducts_readWrite]
,@name = N'securedsp-CAS.GetProducts'
,@value = N''
GO

EXECUTE sys.sp_addextendedproperty
@level0type = N'USER'
,@level0name = [casterproducts_read]
,@name = N'securedsp-CAS.GetProducts'
,@value = N''
GO

EXECUTE sys.sp_addextendedproperty
@level0type = N'USER'
,@level0name = [casterproducts_readWrite]
,@name = N'securedsp-CAS.UpsertTaggingCommand'
,@value = N''
GO

EXECUTE sys.sp_addextendedproperty
@level0type = N'USER'
,@level0name = [casterproducts_readWrite]
,@name = N'securedsp-CAS.ResendProductToL3'
,@value = N''
GO

EXECUTE sys.sp_addextendedproperty
@level0type = N'USER'
,@level0name = [casterproducts_readWrite]
,@name = N'securedsp-CAS.UpdateProductLength'
,@value = N''
GO

EXECUTE sys.sp_addextendedproperty
@level0type = N'USER'
,@level0name = [casps_r]
,@name = N'securedsp-CAS.GetTagPrintReasonPhrases'
,@value = N''
GO

EXECUTE sys.sp_addextendedproperty
@level0type = N'USER'
,@level0name = [casterproducts_readWrite]
,@name = N'securedsp-SUL.UpsertSulfurRating'
,@value = N'SendCurrentUser=TRUE'
GO

EXECUTE sys.sp_addextendedproperty
@level0type = N'USER'
,@level0name = [casterproducts_read]
,@name = N'securedsp-SUL.UpsertSulfurRating'
,@value = N'SendCurrentUser=TRUE'
GO


-------------------
--	Security Modules
-------------------
	USE [IHBoxSystem]
	GO

	DECLARE @ModuleId INT

	INSERT INTO [SECURITY].[Modules]([Code],[Name])
	VALUES('caster_products','Caster Products')

	SET @ModuleId = @@IDENTITY

	INSERT INTO [SECURITY].[ModuleActions]([ModuleId],[Code],[Name],[Role])
	VALUES(@ModuleId,'readWrite','Read/Write','casterproducts_readWrite')

	INSERT INTO [SECURITY].ModuleActions(ModuleId,Code,[Name],[Role])
	VALUES (@ModuleId,'read','Read','casterproducts_read')
