import { describe, it, expect } from 'vitest'
import {
  DEFAULT_AUTO_APPROVE_THRESHOLD,
  SECURITY_MODE_AUTO_APPROVE_THRESHOLD,
  getEffectiveAutoApproveThreshold,
  formatSecurityModeStatus,
} from '../securityMode.js'

describe('threshold constants', () => {
  it('security-mode threshold is strictly higher than default', () => {
    expect(SECURITY_MODE_AUTO_APPROVE_THRESHOLD).toBeGreaterThan(DEFAULT_AUTO_APPROVE_THRESHOLD)
  })

  it('both thresholds are within [0, 1]', () => {
    expect(DEFAULT_AUTO_APPROVE_THRESHOLD).toBeGreaterThanOrEqual(0)
    expect(DEFAULT_AUTO_APPROVE_THRESHOLD).toBeLessThanOrEqual(1)
    expect(SECURITY_MODE_AUTO_APPROVE_THRESHOLD).toBeGreaterThanOrEqual(0)
    expect(SECURITY_MODE_AUTO_APPROVE_THRESHOLD).toBeLessThanOrEqual(1)
  })
})

describe('getEffectiveAutoApproveThreshold', () => {
  it('returns the default threshold when security mode is off', () => {
    expect(getEffectiveAutoApproveThreshold(false)).toBe(DEFAULT_AUTO_APPROVE_THRESHOLD)
  })

  it('returns the security-mode threshold when on', () => {
    expect(getEffectiveAutoApproveThreshold(true)).toBe(SECURITY_MODE_AUTO_APPROVE_THRESHOLD)
  })
})

describe('formatSecurityModeStatus', () => {
  it('reports "off" clearly', () => {
    const s = formatSecurityModeStatus(false)
    expect(s).toMatch(/off/i)
  })

  it('reports "on" and names what it changes', () => {
    const s = formatSecurityModeStatus(true)
    expect(s).toMatch(/on/i)
    // Must mention the tighter auto-approval behavior so users know the mode's effect
    expect(s).toMatch(/auto-approv/i)
    expect(s).toContain(`${Math.round(SECURITY_MODE_AUTO_APPROVE_THRESHOLD * 100)}%`)
  })
})
