import { describe, expect, it, vi } from 'vitest'

describe('IL tax rate seed integrity', () => {
  it('matches the spec-level row counts and structural expectations', async () => {
    const { assertIlTaxRatesIntegrity } = await import('../../src/seed/tax-rates.seed')

    expect(assertIlTaxRatesIntegrity()).toEqual({
      totalRows: 56,
      corporateRows: 12,
      withholdingRows: 2,
      personalBracketRows: 42,
      personalBracketYears: [
        '2015-01-01',
        '2017-01-01',
        '2020-01-01',
        '2022-01-01',
        '2023-01-01',
        '2024-01-01',
        '2025-01-01',
      ],
    })
  })

  it('passes the supplied createdBy id through to every inserted row', async () => {
    const insertedRows: Array<Record<string, unknown>> = []
    const db = {
      insert: vi.fn(() => ({
        values: vi.fn((rows: Array<Record<string, unknown>>) => {
          insertedRows.push(...rows)
          return {
            onConflictDoNothing: vi.fn().mockResolvedValue(undefined),
          }
        }),
      })),
    }

    const { seedTaxRates } = await import('../../src/seed/tax-rates.seed')
    await seedTaxRates(db as never, 'admin-user-1')

    expect(insertedRows).toHaveLength(56)
    expect(new Set(insertedRows.map((row) => row.createdBy))).toEqual(new Set(['admin-user-1']))
  })
})
