-------------
-- ROLES
-------------
	USE [IHBoxSystem]
	GO
	CREATE ROLE eafelectrodessummary_read AUTHORIZATION dbo
	GO

	USE [IHBoxSystem]
	GO
	EXEC sp_addrolemember 'eafelectrodessummary_read', 'admin'
	GO

	USE [IHBoxSystem]
	GO
	EXEC sp_addrolemember 'eafelectrodessummary_read', 'SDI/australtek'
	GO


	CREATE ROLE eafelectrodessummary_readWrite AUTHORIZATION dbo
	GO

	USE [IHBoxSystem]
	GO
	EXEC sp_addrolemember 'eafelectrodessummary_readWrite', 'admin'
	GO

	USE [IHBoxSystem]
	GO
	EXEC sp_addrolemember 'eafelectrodessummary_readWrite', 'SDI/australtek'
	GO


-------------------
-- Menu and Route
-- Lives under EAF -> Electrodes (same place as the legacy "Electrodes Summary")
-------------------
	declare @eafParent int, @electrodesParent int, @result_routeId INT

	select @eafParent = id from [FrontEnd].[Menu]
		where [Name] = 'EAF' and Parent is null

	select @electrodesParent = id from [FrontEnd].[Menu]
		where [Name] = 'Electrodes' and Parent = @eafParent

	INSERT INTO [FrontEnd].[Routes]
			   ([Route]
			   ,[ModuleName]
			   ,[ModulePath]
			   ,[RequiredRole]
		   )
		 VALUES
			   (
			   '!/eaf-electrodes-summary(/:start)(/:end)(/:furnaceCode)(/)'
			   , 'eaf-electrodes-summary'
			   , 'pages/eaf/eaf-electrodes-summary/'
			   , 'eafelectrodessummary_read'
			   )
			   SET @result_routeId = @@IDENTITY
	INSERT INTO [FrontEnd].[Menu]
			   ([Parent]
			   ,[Name]
			   ,[RouteID]
			   ,[SortOrder]
			   ,[Enabled]
			   ,[Visible]
			   ,[RequiredRole]
			   ,[Group]
			  )
		 VALUES
			   (
			   @electrodesParent
			   ,'Electrodes Summary'
			   ,@result_routeId
			   ,1
			   ,1
			   ,1
			   ,'eafelectrodessummary_read'
			   ,NULL
			 )
	GO


-------------------
-- SP Permissions
-- (reuses the existing SP MES.EAF.GetElectrodesReportWeb — no SP changes)
-------------------
GO

EXECUTE sys.sp_addextendedproperty
@level0type = N'USER' -- The object type
,@level0name = [eafelectrodessummary_read] -- The role
,@name = N'securedsp-EAF.GetElectrodesReportWeb' -- the procedure
,@value = N''
GO


EXECUTE sys.sp_addextendedproperty
@level0type = N'USER' -- The object type
,@level0name = [eafelectrodessummary_readWrite] -- The role
,@name = N'securedsp-EAF.GetElectrodesReportWeb' -- the procedure
,@value = N''
GO


-------------------
--	Profiles
-------------------
	USE [IHBoxSystem]
	GO

	DECLARE @ModuleId INT

	INSERT INTO [SECURITY].[Modules]([Code],[Name])
	VALUES('eaf_electrodes_summary','EAF Electrodes Summary')

	SET @ModuleId = @@IDENTITY

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


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