import { describe, expect, it } from 'vitest';
import { ROLES, defaultRoleFor, roleById, rolesFor } from '../src/data/roster';
import { VENUES } from '../src/data/venues';

describe('the roster board', () => {
  it('every venue has at least one shift pinned to it', () => {
    for (const v of VENUES) {
      expect(rolesFor(v.id).length, `${v.id} board is empty`).toBeGreaterThan(0);
    }
  });

  it('every role is pinned to a real venue', () => {
    const ids = new Set(VENUES.map((v) => v.id));
    for (const r of ROLES) {
      expect(r.venues.length).toBeGreaterThan(0);
      for (const vid of r.venues) expect(ids.has(vid), `${r.id} references '${vid}'`).toBe(true);
    }
  });

  it('the ladder pays upward — the boss venues pay the most', () => {
    for (const r of ROLES) expect(r.wage).toBeGreaterThan(0);
    const hos = roleById('hos')!;
    for (const r of ROLES) expect(hos.wage).toBeGreaterThanOrEqual(r.wage);
  });

  it('posts belong to floor starts — you cannot hold the taps from the door', () => {
    for (const r of ROLES) {
      if (r.post) expect(r.startLoc).toBe('floor');
    }
  });

  it('defaultRoleFor always resolves (dev routes skip the board)', () => {
    for (const v of VENUES) {
      const d = defaultRoleFor(v);
      expect(d).toBeDefined();
      // the sensible default mans the door, or is the HoS at boss venues
      expect(d.startLoc).toBe('door');
    }
  });

  it('roleById round-trips and rejects nonsense', () => {
    for (const r of ROLES) expect(roleById(r.id)?.id).toBe(r.id);
    expect(roleById('mascot')).toBeUndefined();
    expect(roleById(undefined)).toBeUndefined();
  });
});
