-- Migration: timbaserad distansspårning + helgdagsoverride
-- Kör i phpMyAdmin: välj rätt databas → SQL-fliken → klistra in → Kör

-- 1. Lägg till timkolumner i work_location_log
ALTER TABLE work_location_log
  ADD COLUMN IF NOT EXISTS office_hours DECIMAL(4,2) NOT NULL DEFAULT 0,
  ADD COLUMN IF NOT EXISTS remote_hours DECIMAL(4,2) NOT NULL DEFAULT 0;

-- 2. Uppdatera location-enum för att tillåta 'mixed'
ALTER TABLE work_location_log
  MODIFY COLUMN location ENUM('office','remote','mixed') NOT NULL DEFAULT 'office';

-- 3. Bakåtkompatibilitet: fyll i timmar för befintliga rader (antar 8h/dag)
UPDATE work_location_log SET office_hours = 8 WHERE location = 'office' AND office_hours = 0;
UPDATE work_location_log SET remote_hours = 8 WHERE location = 'remote' AND remote_hours = 0;

-- 4. Tabell för helgdagsoverrides (markera röda dagar som arbetsdagar)
CREATE TABLE IF NOT EXISTS holiday_overrides (
  date DATE NOT NULL,
  is_working_day TINYINT(1) NOT NULL DEFAULT 1,
  note VARCHAR(255) DEFAULT '',
  created_at DATETIME DEFAULT NOW(),
  PRIMARY KEY (date)
);

-- Vanliga fel (ignorera):
-- #1060 — Kolumnen finns redan
-- #1050 — Tabellen finns redan
-- #1265 — ENUM-värdet ändrades men data är ok
