import { describe, expect, test } from 'vitest';
import { TAX_RATE_OPTIONS, TAX_RATES_CHECKSUM, TAX_RATES_RAW } from '../taxRates.js';

describe('taxRates', () => {
  test('tax rate options exported for consumers', () => {
    expect(TAX_RATE_OPTIONS.length).toBeGreaterThan(0);
    expect(TAX_RATE_OPTIONS[0]).toEqual(expect.objectContaining({ index: 0, year: 1, decimal: 0.01 }));
  });

  test('tax rate options have required fields', () => {
    TAX_RATE_OPTIONS.forEach((option, idx) => {
      expect(option.index).toBe(idx);
      expect(option.year).toBeGreaterThan(0);
      expect(option.daily).toBeGreaterThan(0);
      expect(option.decimal).toBeGreaterThan(0);
      expect(option.decimal).toBe(option.year / 100);
    });
  });

  test('tax rates are in ascending order', () => {
    for (let i = 1; i < TAX_RATE_OPTIONS.length; i++) {
      expect(TAX_RATE_OPTIONS[i].year).toBeGreaterThan(TAX_RATE_OPTIONS[i - 1].year);
    }
  });
});

describe('TAX_RATES_RAW', () => {
  test('is a non-empty array of positive numbers', () => {
    expect(Array.isArray(TAX_RATES_RAW)).toBe(true);
    expect(TAX_RATES_RAW.length).toBeGreaterThan(0);
    TAX_RATES_RAW.forEach(rate => {
      expect(typeof rate).toBe('number');
      expect(rate).toBeGreaterThan(0);
    });
  });

  test('matches TAX_RATE_OPTIONS year values', () => {
    expect(TAX_RATES_RAW.length).toBe(TAX_RATE_OPTIONS.length);
    TAX_RATES_RAW.forEach((raw, idx) => {
      expect(raw).toBe(TAX_RATE_OPTIONS[idx].year);
    });
  });

  test('first entry is 1 and last entry is 9700', () => {
    expect(TAX_RATES_RAW[0]).toBe(1);
    expect(TAX_RATES_RAW[TAX_RATES_RAW.length - 1]).toBe(9700);
  });
});

describe('TAX_RATES_CHECKSUM', () => {
  test('is a non-empty string', () => {
    expect(typeof TAX_RATES_CHECKSUM).toBe('string');
    expect(TAX_RATES_CHECKSUM.length).toBeGreaterThan(0);
  });

  test('has expected format (16 hex chars)', () => {
    expect(TAX_RATES_CHECKSUM).toMatch(/^[0-9a-f]{16}$/);
  });

  test('has known value', () => {
    expect(TAX_RATES_CHECKSUM).toBe('1e37f2312ef082e9');
  });
});
