import { describe, expect, it } from 'vitest';
import {
  guildLocalDateTimeToUtc,
  isValidTimezone,
  resolveScheduleRunAt
} from './timezone.js';

describe('timezone helpers', () => {
  it('validates IANA timezones', () => {
    expect(isValidTimezone('Europe/Berlin')).toBe(true);
    expect(isValidTimezone('Not/AZone')).toBe(false);
  });

  it('converts Berlin winter wall time to UTC', () => {
    // 2026-01-15 09:00 Europe/Berlin = 08:00 UTC (CET, UTC+1)
    const utc = guildLocalDateTimeToUtc('2026-01-15T09:00', 'Europe/Berlin');
    expect(utc.toISOString()).toBe('2026-01-15T08:00:00.000Z');
  });

  it('converts Berlin summer wall time to UTC', () => {
    // 2026-07-15 09:00 Europe/Berlin = 07:00 UTC (CEST, UTC+2)
    const utc = guildLocalDateTimeToUtc('2026-07-15T09:00', 'Europe/Berlin');
    expect(utc.toISOString()).toBe('2026-07-15T07:00:00.000Z');
  });

  it('keeps absolute ISO strings unchanged', () => {
    const utc = resolveScheduleRunAt('2026-07-15T07:00:00.000Z', 'Europe/Berlin');
    expect(utc.toISOString()).toBe('2026-07-15T07:00:00.000Z');
  });

  it('interprets naive datetime-local in guild timezone', () => {
    const utc = resolveScheduleRunAt('2026-07-15T09:00', 'Europe/Berlin');
    expect(utc.toISOString()).toBe('2026-07-15T07:00:00.000Z');
  });
});
