import { describe, expect, it } from 'vitest'
import { generateSageAnalysis } from '../sage-analysis'

const thresholds = {
  excellent: 'Excellent coverage.',
  good: 'Good coverage.',
  moderate: 'Moderate coverage.',
  poor: 'Poor coverage.',
  critical: 'Critical issues detected.',
}

describe('generateSageAnalysis', () => {
  it('returns excellent for score >= 80', () => {
    expect(generateSageAnalysis(80, thresholds)).toBe('Excellent coverage.')
    expect(generateSageAnalysis(100, thresholds)).toBe('Excellent coverage.')
  })

  it('returns good for score >= 60', () => {
    expect(generateSageAnalysis(60, thresholds)).toBe('Good coverage.')
    expect(generateSageAnalysis(79, thresholds)).toBe('Good coverage.')
  })

  it('returns moderate for score >= 40', () => {
    expect(generateSageAnalysis(40, thresholds)).toBe('Moderate coverage.')
    expect(generateSageAnalysis(59, thresholds)).toBe('Moderate coverage.')
  })

  it('returns poor for score < 40', () => {
    expect(generateSageAnalysis(39, thresholds)).toBe('Poor coverage.')
    expect(generateSageAnalysis(0, thresholds)).toBe('Poor coverage.')
  })

  it('returns critical override when flagged', () => {
    expect(generateSageAnalysis(90, thresholds, true)).toBe('Critical issues detected.')
  })

  it('ignores critical flag when no critical message defined', () => {
    const noCtx = { excellent: 'A', good: 'B', moderate: 'C', poor: 'D' }
    expect(generateSageAnalysis(90, noCtx, true)).toBe('A')
  })
})
