SET QUOTED_IDENTIFIER ON

GO

/*
================================================================================
WIP Pages tab — Delays Pareto mirror
================================================================================
Seeds the per-page revamp flag for the Delays Pareto page, registers the proxy
SP and its underlying new-pipeline SP in SEC so the API accepts frontend calls
to both.

All blocks are idempotent (IF NOT EXISTS / Upsert) so re-deploys are safe.
================================================================================
*/

PRINT '--- Post-deployment: Delays Pareto WIP mirror ---';
GO

-- ----------------------------------------------------------------------------
-- 1) Per-page revamp flag for the Delays Pareto proxy.
--    Default '0' = legacy. Flip with:
--        EXEC UTL.SetSetting 'Mill.DBRevampEnabled.DelaysPareto', '1';
-- ----------------------------------------------------------------------------
IF NOT EXISTS (SELECT 1 FROM UTL.catSettings WHERE [SettingName] = 'Mill.DBRevampEnabled.DelaysPareto')
BEGIN
    EXEC UTL.SetSetting 'Mill.DBRevampEnabled.DelaysPareto',
                        'Mill.DBRevampEnabled.DelaysPareto',
                        '0';
    PRINT '  Seeded flag: Mill.DBRevampEnabled.DelaysPareto = ''0''';
END
ELSE
    PRINT '  Skipped flag seed (already exists): Mill.DBRevampEnabled.DelaysPareto';
GO

-- ----------------------------------------------------------------------------
-- 2) Register the proxy SP and the underlying new SP in SEC.
--    The main Pareto page calls the proxy; the WIP Pages variant under
--    /wip-pages/delays/pareto calls [DEL].[GetDelaysForPareto] directly.
-- ----------------------------------------------------------------------------
EXEC [SEC].[UpsertProcedureAndSetToProfile] '[DEL].[GetDelaysForParetoProxy]', 'Admin Profile', 'admin';
GO

EXEC [SEC].[UpsertProcedureAndSetToProfile] '[DEL].[GetDelaysForPareto]',      'Admin Profile', 'admin';
GO

PRINT '--- Post-deployment Delays Pareto WIP mirror complete ---';
GO


/*
================================================================================
WIP Pages tab — Billets Process Data mirror
================================================================================
Seeds the per-page revamp flag for the Billets Process Data page, registers
the two read proxies and their underlying new-pipeline SPs in SEC so the API
accepts frontend calls from both the Reports menu (via the proxies) and the
WIP Pages mirror (via the new SPs directly).

All blocks are idempotent (IF NOT EXISTS / Upsert) so re-deploys are safe.
================================================================================
*/

PRINT '--- Post-deployment: Billets Process Data WIP mirror ---';
GO

-- ----------------------------------------------------------------------------
-- 1) Per-page revamp flag for the Billets Process Data proxies.
--    Default '0' = legacy. Flip with:
--        EXEC UTL.SetSetting 'Mill.DBRevampEnabled.BilletsProcessData', '1';
-- ----------------------------------------------------------------------------
IF NOT EXISTS (SELECT 1 FROM UTL.catSettings WHERE [SettingName] = 'Mill.DBRevampEnabled.BilletsProcessData')
BEGIN
    EXEC UTL.SetSetting 'Mill.DBRevampEnabled.BilletsProcessData',
                        'Mill.DBRevampEnabled.BilletsProcessData',
                        '0';
    PRINT '  Seeded flag: Mill.DBRevampEnabled.BilletsProcessData = ''0''';
END
ELSE
    PRINT '  Skipped flag seed (already exists): Mill.DBRevampEnabled.BilletsProcessData';
GO

-- ----------------------------------------------------------------------------
-- 2) Register the read proxies and the underlying new SPs in SEC.
--    The Reports menu calls the proxies; the WIP Pages variant under
--    /wip-pages/reports/billets-process-data calls the new SPs directly.
-- ----------------------------------------------------------------------------
EXEC [SEC].[UpsertProcedureAndSetToProfile] '[MILL].[GetBilletsProcessDataWebProxy]',        'Admin Profile', 'admin';
GO

EXEC [SEC].[UpsertProcedureAndSetToProfile] '[MILL].[GetBilletsProcessPickersDataWebProxy]', 'Admin Profile', 'admin';
GO

EXEC [SEC].[UpsertProcedureAndSetToProfile] '[MILL].[GetBilletsProcessDataWeb]',             'Admin Profile', 'admin';
GO

EXEC [SEC].[UpsertProcedureAndSetToProfile] '[MILL].[GetBilletsProcessPickersDataWeb]',      'Admin Profile', 'admin';
GO

PRINT '--- Post-deployment Billets Process Data WIP mirror complete ---';
GO
