-- Planning Workstation Config — per-weekday shift hours per machine
-- One row per workstation: default shift hours for each day of the week.
-- Per-date exceptions live in llx_planning_capacity_override.
-- PHASE 4 — created 2026-03-27

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS llx_planning_ws_config (
    rowid       INT UNSIGNED NOT NULL AUTO_INCREMENT,
    fk_ws       INT UNSIGNED NOT NULL,              -- llx_workstation_workstation.rowid
    shift_start        TINYINT UNSIGNED  NOT NULL DEFAULT 6, -- shift start hour 0-23 (e.g. 6 = 06:00)
    changeover_minutes SMALLINT UNSIGNED NOT NULL DEFAULT 0,  -- setup/changeover gap between consecutive MOs (minutes)
    hrs_mon     DECIMAL(4,1) NOT NULL DEFAULT 12,
    hrs_tue     DECIMAL(4,1) NOT NULL DEFAULT 12,
    hrs_wed     DECIMAL(4,1) NOT NULL DEFAULT 12,
    hrs_thu     DECIMAL(4,1) NOT NULL DEFAULT 12,
    hrs_fri     DECIMAL(4,1) NOT NULL DEFAULT 12,
    hrs_sat     DECIMAL(4,1) NOT NULL DEFAULT 0,
    hrs_sun     DECIMAL(4,1) NOT NULL DEFAULT 0,
    entity      INT NOT NULL DEFAULT 1,
    tms         TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,

    PRIMARY KEY (rowid),
    UNIQUE KEY uq_ws_config (fk_ws, entity),
    KEY idx_ws_config_entity (entity),
    KEY idx_ws_config_ws     (entity, fk_ws)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
