import { describe, it, expect } from 'vitest';
import { TeamSummaryViewModel } from './TeamSummaryViewModel';
import type { TeamListItemDTO } from '@/lib/types/generated/GetAllTeamsOutputDTO';

const createTeamListItemDto = (overrides: Partial<TeamListItemDTO> = {}): TeamListItemDTO => ({
  id: 'team-1',
  name: 'Test Team',
  tag: 'TT',
  memberCount: 5,
  description: 'A test team',
  specialization: 'endurance',
  region: 'EU',
  languages: ['en'],
  leagues: ['league-1'],
  ...overrides,
});

describe('TeamSummaryViewModel', () => {
  it('maps fields from DTO', () => {
    const dto = createTeamListItemDto({ id: 'team-123', name: 'Custom Team', tag: 'CT', memberCount: 3 });

    const vm = new TeamSummaryViewModel(dto);

    expect(vm.id).toBe('team-123');
    expect(vm.name).toBe('Custom Team');
    expect(vm.tag).toBe('CT');
    expect(vm.memberCount).toBe(3);
    expect(vm.description).toBe('A test team');
    expect(vm.specialization).toBe('endurance');
    expect(vm.region).toBe('EU');
    expect(vm.languages).toEqual(['en']);
    expect(vm.leagues).toEqual(['league-1']);
  });

  it('derives isFull and related displays when team is full', () => {
    const dto = createTeamListItemDto({ memberCount: 10 });
    const vm = new TeamSummaryViewModel(dto);

    expect(vm.isFull).toBe(true);
    expect(vm.memberCountDisplay).toBe('10/10');
    expect(vm.statusIndicator).toBe('Full');
    expect(vm.statusColor).toBe('red');
  });

  it('derives isFull and related displays when team is not full', () => {
    const dto = createTeamListItemDto({ memberCount: 3 });
    const vm = new TeamSummaryViewModel(dto);

    expect(vm.isFull).toBe(false);
    expect(vm.memberCountDisplay).toBe('3/10');
    expect(vm.statusIndicator).toBe('Open');
    expect(vm.statusColor).toBe('green');
  });

  it('formats tagDisplay with square brackets', () => {
    const dto = createTeamListItemDto({ tag: 'TT' });
    const vm = new TeamSummaryViewModel(dto);

    expect(vm.tagDisplay).toBe('[TT]');
  });
});
