import { describe, expect, it } from 'vitest';
import { evaluateVisibility, normalizeRoleKey, schemaIdFromInput } from './onboarding-flow';

describe('normalizeRoleKey', () => {
  it('normalizes case and separators', () => {
    expect(normalizeRoleKey('job seeker')).toBe('JOB_SEEKER');
    expect(normalizeRoleKey('job-seeker')).toBe('JOB_SEEKER');
    expect(normalizeRoleKey(' photographer ')).toBe('PHOTOGRAPHER');
  });
});

describe('schemaIdFromInput', () => {
  it('maps major role schemas', () => {
    expect(schemaIdFromInput('CUSTOMER', '')).toBe('customer_onboarding_v1');
    expect(schemaIdFromInput('COMPANY', '')).toBe('company_onboarding_v1');
    expect(schemaIdFromInput('JOB_SEEKER', '')).toBe('jobseeker_onboarding_v1');
    expect(schemaIdFromInput('jobseeker', '')).toBe('jobseeker_onboarding_v1');
  });

  it('maps professional sub-role keys directly', () => {
    expect(schemaIdFromInput('PHOTOGRAPHER', '')).toBe('photographer_onboarding_v1');
    expect(schemaIdFromInput('MAKEUP_ARTIST', '')).toBe('makeup_artist_onboarding_v1');
    expect(schemaIdFromInput('TUTOR', '')).toBe('tutor_onboarding_v1');
    expect(schemaIdFromInput('DEVELOPER', '')).toBe('developer_onboarding_v1');
    expect(schemaIdFromInput('VIDEO_EDITOR', '')).toBe('video_editor_onboarding_v1');
    expect(schemaIdFromInput('GRAPHIC_DESIGNER', '')).toBe('graphic_designer_onboarding_v1');
    expect(schemaIdFromInput('SOCIAL_MEDIA_MANAGER', '')).toBe('social_media_manager_onboarding_v1');
    expect(schemaIdFromInput('FITNESS_TRAINER', '')).toBe('fitness_trainer_onboarding_v1');
    expect(schemaIdFromInput('CATERING_SERVICES', '')).toBe('catering_services_onboarding_v1');
  });

  it('maps professional schema with profession key', () => {
    expect(schemaIdFromInput('PROFESSIONAL', 'Photographer')).toBe('photographer_onboarding_v1');
    expect(schemaIdFromInput('professional', 'Social Media Manager')).toBe('social_media_manager_onboarding_v1');
    expect(schemaIdFromInput('PROFESSIONAL', 'Fitness-Trainer')).toBe('fitness_trainer_onboarding_v1');
  });

  it('falls back for generic professional when no profession', () => {
    expect(schemaIdFromInput('PROFESSIONAL', '')).toBe('professional_onboarding_v1');
  });
});

describe('evaluateVisibility', () => {
  it('supports equals conditions', () => {
    const visible = evaluateVisibility(
      [{ field: 'profession', equals: 'photographer' }],
      { profession: 'photographer' },
    );
    expect(visible).toBe(true);
  });

  it('supports in conditions', () => {
    const visible = evaluateVisibility(
      [{ field: 'service_mode', in: ['remote', 'hybrid'] }],
      { service_mode: 'hybrid' },
    );
    expect(visible).toBe(true);
  });

  it('returns false when condition mismatches', () => {
    const visible = evaluateVisibility(
      [{ field: 'profession', equals: 'developer' }],
      { profession: 'tutor' },
    );
    expect(visible).toBe(false);
  });
});
