import { describe, it, expect } from 'vitest';
import { SponsorshipPricingViewModel } from './SponsorshipPricingViewModel';

describe('SponsorshipPricingViewModel', () => {
  const dto = {
    mainSlotPrice: 10_000,
    secondarySlotPrice: 6_000,
    currency: 'USD',
  } as any;

  it('maps basic pricing fields from DTO', () => {
    const vm = new SponsorshipPricingViewModel(dto);

    expect(vm.mainSlotPrice).toBe(dto.mainSlotPrice);
    expect(vm.secondarySlotPrice).toBe(dto.secondarySlotPrice);
    expect(vm.currency).toBe(dto.currency);
  });

  it('exposes formatted prices and price difference', () => {
    const vm = new SponsorshipPricingViewModel(dto);

    expect(vm.formattedMainSlotPrice).toBe(`${dto.currency} ${dto.mainSlotPrice.toLocaleString()}`);
    expect(vm.formattedSecondarySlotPrice).toBe(`${dto.currency} ${dto.secondarySlotPrice.toLocaleString()}`);

    const expectedDiff = dto.mainSlotPrice - dto.secondarySlotPrice;
    expect(vm.priceDifference).toBe(expectedDiff);
    expect(vm.formattedPriceDifference).toBe(`${dto.currency} ${expectedDiff.toLocaleString()}`);
  });

  it('computes discount percentage for secondary slots', () => {
    const vm = new SponsorshipPricingViewModel(dto);

    const expectedDiscount = Math.round((1 - dto.secondarySlotPrice / dto.mainSlotPrice) * 100);
    expect(vm.secondaryDiscountPercentage).toBe(expectedDiscount);

    const zeroMain = new SponsorshipPricingViewModel({ ...dto, mainSlotPrice: 0 });
    expect(zeroMain.secondaryDiscountPercentage).toBe(0);
  });
});
