-- Add plan_categories table and convert category columns from ENUM to VARCHAR(50)

-- CreateTable
CREATE TABLE `plan_categories` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `key` VARCHAR(50) NOT NULL,
    `label` VARCHAR(100) NOT NULL,
    `color` VARCHAR(7) NOT NULL,
    `sort_order` INTEGER NOT NULL DEFAULT 0,
    `is_active` BOOLEAN NOT NULL DEFAULT true,
    `created_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
    `updated_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),

    UNIQUE INDEX `plan_categories_key_key`(`key`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AlterTable: change category from ENUM to VARCHAR(50) in work_plan_entries
ALTER TABLE `work_plan_entries` MODIFY `category` VARCHAR(50) NOT NULL DEFAULT 'work';

-- AlterTable: change category from ENUM to VARCHAR(50) in work_plan_overrides
ALTER TABLE `work_plan_overrides` MODIFY `category` VARCHAR(50) NOT NULL;

-- Seed the categories that were previously the plan_category enum
INSERT INTO `plan_categories` (`key`, `label`, `color`, `sort_order`, `is_active`) VALUES
  ('work',        'Práce',          '#2563eb', 1, true),
  ('preparation', 'Příprava',       '#0d9488', 2, true),
  ('travel',      'Cesta / Montáž', '#ca8a04', 3, true),
  ('leave',       'Dovolená',       '#16a34a', 4, true),
  ('sick',        'Nemoc',          '#dc2626', 5, true),
  ('training',    'Školení',        '#7c3aed', 6, true),
  ('other',       'Jiné',           '#6b7280', 7, true);
