import { describe, expect, it, vi } from 'vitest'
vi.mock('server-only', () => ({}))
import { routeTextsToDescription } from '@/lib/adapters/flask'
import { includedRouteStatusLabel, permitRouteLabel } from '@/lib/domain/permit-routes'

describe('route text from the Brain, in every shape', () => {
  it('joins the 3-line list', () => {
    expect(routeTextsToDescription(['Houston, TX', 'Dallas, TX', 'I-45 N'])).toBe('Houston, TX Dallas, TX I-45 N')
  })
  it('parses a list written into one string, so no brackets show', () => {
    expect(routeTextsToDescription('["Houston, TX", "Dallas, TX", "I-45 N"]')).toBe('Houston, TX Dallas, TX I-45 N')
  })
  it('keeps a plain string, including one that only looks bracketed', () => {
    expect(routeTextsToDescription('I-10 E to the state line')).toBe('I-10 E to the state line')
    expect(routeTextsToDescription('[not json]')).toBe('[not json]')
  })
  it('reads the object form', () => {
    expect(routeTextsToDescription({ routing_from: 'Charleston', routing_to: 'Georgia state line', via: 'I-20' })).toBe('Charleston Georgia state line I-20')
  })
  it('treats empty input as no text', () => {
    expect(routeTextsToDescription([])).toBeUndefined()
    expect(routeTextsToDescription('  ')).toBeUndefined()
    expect(routeTextsToDescription(null)).toBeUndefined()
  })
})

describe('a permit with no route text', () => {
  it('reads as a route being prepared, not an error', () => {
    expect(permitRouteLabel('no_route_text')).toBe('Route prepared from your permit')
    expect(includedRouteStatusLabel('no_route_text')).toBe('Route prepared from your permit')
  })
})
