import { describe, it, expect } from 'vitest';
import { DriverTeamViewModel } from './DriverTeamViewModel';
import type { GetDriverTeamOutputDTO } from '@/lib/types/generated/GetDriverTeamOutputDTO';

const createTeamDto = (overrides: Partial<GetDriverTeamOutputDTO> = {}): GetDriverTeamOutputDTO => ({
  team: {
    id: 'team-1',
    name: 'Test Team',
    tag: 'TT',
    description: 'Test team description',
    ownerId: 'owner-1',
    leagues: ['league-1'],
    createdAt: '2024-01-01T00:00:00Z',
    specialization: 'mixed',
    region: 'EU',
    languages: ['en'],
  },
  membership: {
    role: 'manager',
    joinedAt: '2024-01-01T00:00:00Z',
    isActive: true,
  },
  isOwner: false,
  canManage: true,
  ...overrides,
});

describe('DriverTeamViewModel', () => {
  it('maps team and membership fields from DTO', () => {
    const dto = createTeamDto();
    const viewModel = new DriverTeamViewModel(dto);

    expect(viewModel.teamId).toBe('team-1');
    expect(viewModel.teamName).toBe('Test Team');
    expect(viewModel.tag).toBe('TT');
    expect(viewModel.role).toBe('manager');
    expect(viewModel.isOwner).toBe(false);
    expect(viewModel.canManage).toBe(true);
  });

  it('derives displayRole with capitalized first letter', () => {
    const dto = createTeamDto({
      membership: {
        role: 'owner',
        joinedAt: '2024-01-01T00:00:00Z',
        isActive: true,
      },
    });

    const viewModel = new DriverTeamViewModel(dto);

    expect(viewModel.displayRole).toBe('Owner');
  });

  it('handles lower-case role strings consistently', () => {
    const dto = createTeamDto({
      membership: {
        role: 'member',
        joinedAt: '2024-01-01T00:00:00Z',
        isActive: true,
      },
    });

    const viewModel = new DriverTeamViewModel(dto);

    expect(viewModel.displayRole).toBe('Member');
  });
});
