import { describe, expect, it } from 'vitest';
import {
  toLearnedSignIds,
  toZoneColor,
} from '@/business/user-progress/mappers';
import type { UserProgressDto } from '@/shared/types/userProgress';

function createProgress(overrides: Partial<UserProgressDto> = {}): UserProgressDto {
  return {
    id: 'progress-1',
    progress_type: 'sign_learned',
    item_id: 'hello',
    value: null,
    score: null,
    metadata: null,
    organizationId: 'org-1',
    campusId: 'campus-1',
    userId: 'user-1',
    createdAt: '2026-06-08T12:00:00.000Z',
    updatedAt: '2026-06-08T12:00:00.000Z',
    ...overrides,
  };
}

describe('user progress mappers', () => {
  it('maps learned sign progress rows to a unique id set', () => {
    const learnedSignIds = toLearnedSignIds([
      createProgress({ id: '1', item_id: 'hello' }),
      createProgress({ id: '2', item_id: 'help' }),
      createProgress({ id: '3', item_id: 'hello' }),
    ]);

    expect([...learnedSignIds].sort()).toEqual(['hello', 'help']);
  });

  it('normalizes valid zone colors and rejects invalid values', () => {
    expect(toZoneColor('blue')).toBe('blue');
    expect(toZoneColor('green')).toBe('green');
    expect(toZoneColor('yellow')).toBe('yellow');
    expect(toZoneColor('red')).toBe('red');
    expect(toZoneColor('purple')).toBeNull();
    expect(toZoneColor(null)).toBeNull();
  });
});
