-- ─────────────────────────────────────────────────────────────────────────────
-- Migration: Add FUNCTION_DEPT_REF_ID to TTM_CLIENT_FL_MAPPING
-- Purpose  : Support function-based FL assignment — each mapping row now
--            represents one FL assigned to one function (department) for a
--            client contract document.
-- ─────────────────────────────────────────────────────────────────────────────

ALTER TABLE `TTM_CLIENT_FL_MAPPING`
  ADD COLUMN `FUNCTION_DEPT_REF_ID` int DEFAULT NULL
    COMMENT 'FK → departments.ID — the function/department this FL is assigned for'
  AFTER `FL_EMP_REF_ID`;

ALTER TABLE `TTM_CLIENT_FL_MAPPING`
  ADD COLUMN `TASK_ASSIGNED` tinyint(1) NOT NULL DEFAULT 0
    COMMENT '1 = admin has created a task for this mapping'
  AFTER `ACTIVE`;

ALTER TABLE `TTM_CLIENT_FL_MAPPING`
  ADD INDEX `idx_function_dept` (`FUNCTION_DEPT_REF_ID`),
  ADD INDEX `idx_task_assigned`  (`TASK_ASSIGNED`);
