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

import { detectUseCase, type UseCaseLite } from './controls-augmentation'

const UCS: UseCaseLite[] = [
  { key: 'impressum', label: 'Impressum (§5 TMG/DDG)', regulations: ['TMG', 'DDG'], mapped_controls: 9 },
  { key: 'dse', label: 'Datenschutzerklärung', regulations: ['DSGVO'], mapped_controls: 4610 },
  { key: 'network_security', label: 'Network Security', regulations: ['ISO 27001'], mapped_controls: 5095 },
  { key: 'agb', label: 'AGB', regulations: ['BGB'], mapped_controls: 433 },
]

describe('detectUseCase', () => {
  it('matches Impressum by key + label', () => {
    expect(detectUseCase('Nenne alle Controls für Impressum', UCS)?.key).toBe('impressum')
  })

  it('matches DSE via the full label word', () => {
    expect(detectUseCase('Was gilt für die Datenschutzerklärung?', UCS)?.key).toBe('dse')
  })

  it('matches DSE via prefix (Datenschutz → Datenschutzerklärung)', () => {
    expect(detectUseCase('Welche Datenschutz Pflichten gibt es?', UCS)?.key).toBe('dse')
  })

  it('matches network_security via the multi-word key', () => {
    expect(detectUseCase('zeig mir network security controls', UCS)?.key).toBe('network_security')
  })

  it('matches AGB by key token', () => {
    expect(detectUseCase('Pflichtangaben in den AGB?', UCS)?.key).toBe('agb')
  })

  it('returns null when no topic is mentioned', () => {
    expect(detectUseCase('Wie spät ist es?', UCS)).toBeNull()
  })
})
