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

vi.mock('../../lib/prisma', () => ({
  prisma: {
    pricingRule: { findMany: vi.fn() },
    customer: { findUniqueOrThrow: vi.fn() },
  },
}))

import { calculateUpdatedAdditionalDriverCharge, calculateUpdatedInsuranceCharge } from './reservation.pricing.service'

describe('reservation pricing helpers', () => {
  it('calculates insurance charges for every supported billing model', () => {
    expect(calculateUpdatedInsuranceCharge('PER_DAY', 40, 5, 1000)).toBe(200)
    expect(calculateUpdatedInsuranceCharge('PER_RENTAL', 125, 5, 1000)).toBe(125)
    expect(calculateUpdatedInsuranceCharge('PERCENTAGE_OF_RENTAL', 12.5, 5, 1000)).toBe(125)
  })

  it('rounds percentage insurance charges to whole minor units', () => {
    expect(calculateUpdatedInsuranceCharge('PERCENTAGE_OF_RENTAL', 7.5, 3, 999)).toBe(75)
  })

  it('calculates additional driver charges for paid and free models', () => {
    expect(calculateUpdatedAdditionalDriverCharge('PER_DAY', 25, 4)).toBe(100)
    expect(calculateUpdatedAdditionalDriverCharge('FLAT', 60, 4)).toBe(60)
    expect(calculateUpdatedAdditionalDriverCharge('FREE', 999, 4)).toBe(0)
  })
})
