-- Section A 동시 개발 대비: 필요 테이블/컬럼 IF NOT EXISTS로 안전 생성

CREATE TABLE IF NOT EXISTS company_holidays (
  id INT AUTO_INCREMENT PRIMARY KEY,
  holiday_date DATE NOT NULL,
  holiday_name VARCHAR(100) NOT NULL,
  holiday_type ENUM('PAID', 'ANNUAL_DEDUCT') NOT NULL,
  description TEXT,
  created_by INT NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (created_by) REFERENCES sso_users(user_id),
  UNIQUE KEY uq_holiday_date (holiday_date)
);

-- Section C 전용: 중복 차감 방지
ALTER TABLE company_holidays
  ADD COLUMN IF NOT EXISTS deduction_applied_at TIMESTAMP NULL
    COMMENT '연차차감 실행 시각 (NULL=미실행)';

-- sp_vacation_balances 컬럼 추가 (Section A 대비)
ALTER TABLE sp_vacation_balances
  ADD COLUMN IF NOT EXISTS balance_type ENUM('AUTO','MANUAL','CARRY_OVER','LONG_SERVICE','COMPANY_GRANT')
    DEFAULT 'AUTO';
ALTER TABLE sp_vacation_balances
  ADD COLUMN IF NOT EXISTS expires_at DATE NULL;
