import { describe, it, expect } from 'vitest'
import { estimateMarketRent, suggestFutureRent } from '../rentEstimate'

describe('estimateMarketRent', () => {
  // Zürich OFFICE median = 42/Monat → 504/Jahr (getMarketRent rechnet ×12)
  it('flags asking rent clearly above the city median as ABOVE', () => {
    const est = estimateMarketRent('Zürich', 'OFFICE', 600)
    expect(est).not.toBeNull()
    expect(est!.verdict).toBe('ABOVE')
    expect(est!.deltaPct).toBeGreaterThan(5)
    expect(est!.fairRentPerSqm).toBe(504)
  })

  it('flags asking rent clearly below median as BELOW', () => {
    const est = estimateMarketRent('Zürich', 'OFFICE', 400)
    expect(est!.verdict).toBe('BELOW')
    expect(est!.deltaPct).toBeLessThan(-5)
  })

  it('treats near-median asking rent as AT (within ±5%)', () => {
    const est = estimateMarketRent('Zürich', 'OFFICE', 510)
    expect(est!.verdict).toBe('AT')
  })

  it('returns null for unknown city', () => {
    expect(estimateMarketRent('Atlantis', 'OFFICE', 480)).toBeNull()
  })

  it('suggestFutureRent indexes by the city rent trend', () => {
    // Zürich rentTrend12m = +4.2% → 100 * 1.042 = 104 (rounded)
    expect(suggestFutureRent('Zürich', 100)).toBe(104)
  })
})
