import { test } from 'node:test';
import assert from 'node:assert/strict';
import { ROLE_NAMES, type RoleName } from '@/shared/constants/roles';
import {
  SEED_ALL_USERS,
  SEED_CAMPUS_ID,
  SEED_CLASS_ID,
  SEED_FIXTURE_USERS,
  SEED_SECONDARY_CAMPUS_ID,
  SEED_SECONDARY_CLASS_ID,
  SEED_SECONDARY_SCHOOL_ID,
  SEED_SECONDARY_USERS,
  SEED_SCHOOL_ID,
} from '@/shared/constants/seed-fixtures';

const TENANT_ROLE_NAMES: readonly RoleName[] = [
  ROLE_NAMES.OWNER,
  ROLE_NAMES.SUPERINTENDENT,
  ROLE_NAMES.PRINCIPAL,
  ROLE_NAMES.REGISTRAR,
  ROLE_NAMES.DIRECTOR,
  ROLE_NAMES.OFFICE_MANAGER,
  ROLE_NAMES.TEACHER,
  ROLE_NAMES.SUPPORT_STAFF,
  ROLE_NAMES.STUDENT,
  ROLE_NAMES.GUARDIAN,
];

function rolesOf(users: readonly { readonly role: RoleName }[]): readonly RoleName[] {
  return users.map((user) => user.role);
}

test('primary seed tenant has one login user for every platform role', () => {
  assert.deepEqual(rolesOf(SEED_FIXTURE_USERS), [
    ROLE_NAMES.SUPER_ADMIN,
    ROLE_NAMES.SYSTEM_ADMIN,
    ...TENANT_ROLE_NAMES,
  ]);
});

test('secondary seed tenant has every non-system tenant role', () => {
  assert.deepEqual(rolesOf(SEED_SECONDARY_USERS), TENANT_ROLE_NAMES);
});

test('all seeded users have unique ids and emails', () => {
  const ids = SEED_ALL_USERS.map((user) => user.id);
  const emails = SEED_ALL_USERS.map((user) => user.email);

  assert.equal(new Set(ids).size, ids.length);
  assert.equal(new Set(emails).size, emails.length);
});

test('secondary tenant topology is separate from primary school, campus, and class', () => {
  assert.notEqual(SEED_SECONDARY_SCHOOL_ID, SEED_SCHOOL_ID);
  assert.notEqual(SEED_SECONDARY_CAMPUS_ID, SEED_CAMPUS_ID);
  assert.notEqual(SEED_SECONDARY_CLASS_ID, SEED_CLASS_ID);
});
