-- =====================================================================
-- TTM MASTER DATA SEED
-- Run this once to populate master lookup tables.
-- Uses INSERT IGNORE so it's safe to re-run.
-- =====================================================================

-- ─────────────────────────────────────────────────────────────────────
-- 1. TTM_PRIORITY_MASTER
--    LOW (15+ days) · MEDIUM (7-14) · HIGH (3-6) · CRITICAL (1-2 / overdue)
-- ─────────────────────────────────────────────────────────────────────
INSERT IGNORE INTO `TTM_PRIORITY_MASTER`
  (`PRIORITY_NAME`, `PRIORITY_CODE`, `DAYS_THRESHOLD_FROM`, `DAYS_THRESHOLD_TO`, `COLOR_HEX`, `DESCRIPTION`, `SORT_ORDER`, `DELETED`)
VALUES
  ('Low',      'LOW',      15,   NULL, '#28a745', '15 or more days to deadline – comfortable buffer',          1, 0),
  ('Medium',   'MEDIUM',    7,     14, '#007bff', '7 to 14 days to deadline – monitor progress',               2, 0),
  ('High',     'HIGH',      3,      6, '#fd7e14', '3 to 6 days to deadline – needs immediate attention',       3, 0),
  ('Critical', 'CRITICAL',  1,      2, '#dc3545', '1-2 days to deadline or already past deadline – escalate', 4, 0);


-- ─────────────────────────────────────────────────────────────────────
-- 2. TTM_TASK_TYPE_MASTER
--    FIXED · VARIABLE · FIXED_VARIABLE · GENERAL
-- ─────────────────────────────────────────────────────────────────────
INSERT IGNORE INTO `TTM_TASK_TYPE_MASTER`
  (`TYPE_NAME`, `TYPE_CODE`, `DESCRIPTION`, `SORT_ORDER`, `DELETED`)
VALUES
  ('Fixed',          'FIXED',          'Auto-generated on a recurring schedule (e.g. monthly payroll)',                          1, 0),
  ('Variable',       'VARIABLE',       'One-off task triggered manually by a Functional Lead when needed',                       2, 0),
  ('Fixed Variable', 'FIXED_VARIABLE', 'Recurring but each instance date is event-driven (e.g. board meetings, AGM filings)',    3, 0),
  ('General',        'GENERAL',        'Simple task with no sequential multi-function workflow',                                  4, 0);


-- ─────────────────────────────────────────────────────────────────────
-- 3. TTM_DELAY_CATEGORY_MASTER
--    Common reasons a task function may be delayed
-- ─────────────────────────────────────────────────────────────────────
INSERT IGNORE INTO `TTM_DELAY_CATEGORY_MASTER`
  (`CATEGORY_CODE`, `CATEGORY_NAME`, `ALLOWS_MANUAL_TEXT`, `SORT_ORDER`, `DELETED`)
VALUES
  ('AWAITING_CLIENT',    'Awaiting Client Input',         1, 1, 0),
  ('TECHNICAL_ISSUES',   'Technical Issues',              1, 2, 0),
  ('COMPLEXITY',         'Complexity Underestimated',     1, 3, 0),
  ('REVIEWER_DELAY',     'Reviewer Delay',                1, 4, 0),
  ('RESOURCE_UNAVAIL',   'Resource Unavailability',       1, 5, 0),
  ('DATA_INCOMPLETE',    'Incomplete Data Received',      1, 6, 0),
  ('REGULATORY_CHANGE',  'Regulatory / Policy Change',    1, 7, 0),
  ('OTHER',              'Other',                         1, 8, 0);


-- ─────────────────────────────────────────────────────────────────────
-- 4. TTM_RECURRENCE_RULE_MASTER
--    INTERVAL_MONTHS: NULL=weekly/fortnightly, 1=monthly, 3=quarterly,
--                     6=half-yearly, 12=yearly
--    RECURRENCE_DAY_OF_MONTH: day of month auto-generation fires (1-28)
-- ─────────────────────────────────────────────────────────────────────
INSERT IGNORE INTO `TTM_RECURRENCE_RULE_MASTER`
  (`RULE_NAME`, `RULE_CODE`, `DESCRIPTION`, `INTERVAL_MONTHS`, `RECURRENCE_DAY_OF_MONTH`, `SORT_ORDER`, `DELETED`)
VALUES
  ('Weekly',      'WEEKLY',      'Task generates every 7 days',              NULL,  NULL, 1, 0),
  ('Fortnightly', 'FORTNIGHTLY', 'Task generates every 14 days',             NULL,  NULL, 2, 0),
  ('Monthly',     'MONTHLY',     'Task generates once a month on day 1',        1,     1, 3, 0),
  ('Quarterly',   'QUARTERLY',   'Task generates every 3 months on day 1',      3,     1, 4, 0),
  ('Half-Yearly', 'HALF_YEARLY', 'Task generates every 6 months on day 1',      6,     1, 5, 0),
  ('Yearly',      'YEARLY',      'Task generates once a year on day 1',         12,     1, 6, 0);


-- =====================================================================
-- Done. Verify with:
--   SELECT * FROM TTM_PRIORITY_MASTER;
--   SELECT * FROM TTM_TASK_TYPE_MASTER;
--   SELECT * FROM TTM_DELAY_CATEGORY_MASTER;
--   SELECT * FROM TTM_RECURRENCE_RULE_MASTER;
-- =====================================================================
