import { describe, expect, it } from 'vitest';
import {
  MAX_TIMEOUT_MS,
  parseDuration,
  parseTimeoutDuration,
  tryParseDuration
} from './duration.js';

describe('parseDuration', () => {
  it('parses minutes', () => {
    expect(parseDuration('15m')).toBe(900000);
  });

  it('parses days', () => {
    expect(parseDuration('2d')).toBe(172800000);
  });

  it('throws on invalid strings', () => {
    expect(() => parseDuration('tomorrow')).toThrow();
  });
});

describe('parseTimeoutDuration', () => {
  it('accepts durations within Discord limit', () => {
    expect(parseTimeoutDuration('1d')).toBe(86_400_000);
  });

  it('rejects durations over 28 days', () => {
    expect(() => parseTimeoutDuration('30d')).toThrow(/28/);
  });

  it('exposes MAX_TIMEOUT_MS as 28 days', () => {
    expect(MAX_TIMEOUT_MS).toBe(28 * 24 * 60 * 60 * 1000);
  });
});

describe('tryParseDuration', () => {
  it('returns null for invalid input', () => {
    expect(tryParseDuration('nope')).toBeNull();
  });

  it('returns ms for valid input', () => {
    expect(tryParseDuration('10s')).toBe(10_000);
  });
});
