import { describe, expect, it } from 'vitest';
import {
  buildTeacherCandidateLabel,
  buildTeacherCandidateOptions,
  isTeacherCandidate,
  type TeacherCandidateUser,
} from './teacher-candidate';

const baseUser = (overrides: Partial<TeacherCandidateUser> = {}): TeacherCandidateUser => ({
  id: 1,
  username: 'teacher',
  name: '测试老师',
  isActive: true,
  isArchived: false,
  studentStatus: null,
  roles: [{ code: 'teacher', name: '任课老师' }],
  profile: { subjects: ['数学', '物理'] },
  ...overrides,
});

describe('class teacher candidates', () => {
  it('keeps non-teacher staff roles because class duty is selected separately', () => {
    expect(
      isTeacherCandidate(baseUser({ roles: [{ code: 'academic', name: '教务管理员' }] })),
    ).toBe(true);
  });

  it('keeps staff-linked accounts so they can serve as head or life teachers', () => {
    expect(isTeacherCandidate(baseUser({ studentStatus: 'staff' }))).toBe(true);
  });

  it('excludes active students, disabled, archived, and super-admin accounts', () => {
    const users = [
      baseUser({ id: 1, studentStatus: 'active' }),
      baseUser({ id: 2, isActive: false }),
      baseUser({ id: 3, isArchived: true }),
      baseUser({
        id: 4,
        roles: [{ code: 'super_admin', name: '超级管理员' }],
      }),
    ];

    expect(buildTeacherCandidateOptions(users)).toEqual([]);
  });

  it('shows real name, username, system role, and teaching subjects', () => {
    expect(buildTeacherCandidateLabel(baseUser())).toBe(
      '测试老师（teacher） · 任课老师 · 数学/物理',
    );
  });
});
