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

describe('RenewalAlertViewModel', () => {
  it('maps core fields and derives formatted price and date', () => {
    const vm = new RenewalAlertViewModel({
      id: 'ren-1',
      name: 'League Sponsorship',
      type: 'league',
      renewDate: '2024-01-15',
      price: 100,
    });

    expect(vm.id).toBe('ren-1');
    expect(vm.name).toBe('League Sponsorship');
    expect(vm.type).toBe('league');
    expect(vm.formattedPrice).toBe('$100');
    expect(typeof vm.formattedRenewDate).toBe('string');
  });

  it('maps type to icon name', () => {
    const league = new RenewalAlertViewModel({ id: '1', name: 'A', type: 'league', renewDate: '2024-01-01', price: 0 });
    const team = new RenewalAlertViewModel({ id: '2', name: 'B', type: 'team', renewDate: '2024-01-01', price: 0 });
    const driver = new RenewalAlertViewModel({ id: '3', name: 'C', type: 'driver', renewDate: '2024-01-01', price: 0 });
    const race = new RenewalAlertViewModel({ id: '4', name: 'D', type: 'race', renewDate: '2024-01-01', price: 0 });
    const platform = new RenewalAlertViewModel({ id: '5', name: 'E', type: 'platform', renewDate: '2024-01-01', price: 0 });

    expect(league.typeIcon).toBe('Trophy');
    expect(team.typeIcon).toBe('Users');
    expect(driver.typeIcon).toBe('Car');
    expect(race.typeIcon).toBe('Flag');
    expect(platform.typeIcon).toBe('Megaphone');
  });

  it('computes daysUntilRenewal and urgency flag based on current date', () => {
    const now = new Date();
    const soon = new Date(now.getTime() + 10 * 24 * 60 * 60 * 1000);
    const later = new Date(now.getTime() + 40 * 24 * 60 * 60 * 1000);

    const soonAlert = new RenewalAlertViewModel({
      id: 'soon',
      name: 'Soon',
      type: 'league',
      renewDate: soon.toISOString(),
      price: 0,
    });

    const laterAlert = new RenewalAlertViewModel({
      id: 'later',
      name: 'Later',
      type: 'league',
      renewDate: later.toISOString(),
      price: 0,
    });

    expect(soonAlert.daysUntilRenewal).toBeGreaterThan(0);
    expect(soonAlert.isUrgent).toBe(true);

    expect(laterAlert.daysUntilRenewal).toBeGreaterThan(30);
    expect(laterAlert.isUrgent).toBe(false);
  });
});
