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

describe('SponsorshipRequestViewModel', () => {
  const baseDto = {
    id: 'req-1',
    sponsorId: 'sp-1',
    sponsorName: 'Acme Corp',
    sponsorLogo: '/logo.png',
    tier: 'main' as const,
    offeredAmount: 50_000,
    currency: 'USD',
    formattedAmount: 'USD 50,000',
    message: 'We would like to sponsor your league',
    createdAt: new Date('2025-01-10T00:00:00Z'),
    platformFee: 5_000,
    netAmount: 45_000,
  };

  it('maps DTO fields and keeps date instance', () => {
    const vm = new SponsorshipRequestViewModel(baseDto as any);

    expect(vm.id).toBe(baseDto.id);
    expect(vm.sponsorId).toBe(baseDto.sponsorId);
    expect(vm.sponsorName).toBe(baseDto.sponsorName);
    expect(vm.sponsorLogo).toBe(baseDto.sponsorLogo);
    expect(vm.tier).toBe(baseDto.tier);
    expect(vm.offeredAmount).toBe(baseDto.offeredAmount);
    expect(vm.currency).toBe(baseDto.currency);
    expect(vm.formattedAmount).toBe(baseDto.formattedAmount);
    expect(vm.message).toBe(baseDto.message);
    expect(vm.createdAt).toBeInstanceOf(Date);
    expect(vm.platformFee).toBe(baseDto.platformFee);
    expect(vm.netAmount).toBe(baseDto.netAmount);
  });

  it('formats created date for UI display', () => {
    const fixedNow = new Date('2025-01-10T00:00:00Z');
    vi.setSystemTime(fixedNow);

    const vm = new SponsorshipRequestViewModel(baseDto as any);

    const formatted = vm.formattedDate;
    expect(typeof formatted).toBe('string');
    expect(formatted.length).toBeGreaterThan(0);

    vi.useRealTimers();
  });

  it('exposes net amount in dollars and tier helpers', () => {
    const vmMain = new SponsorshipRequestViewModel(baseDto as any);
    expect(vmMain.netAmountDollars).toBe(`$${(baseDto.netAmount / 100).toFixed(2)}`);
    expect(vmMain.tierDisplay).toBe('Main Sponsor');
    expect(vmMain.tierBadgeVariant).toBe('primary');

    const vmSecondary = new SponsorshipRequestViewModel({ ...baseDto, tier: 'secondary' } as any);
    expect(vmSecondary.tierDisplay).toBe('Secondary');
    expect(vmSecondary.tierBadgeVariant).toBe('secondary');
  });
});
