import { describe, expect, it } from 'vitest';
import {
  filterSchedulesForClass,
  isMaskedSchedule,
  type VisibleSchedule,
} from './schedule-visibility';

const ownSchedule: VisibleSchedule = {
  id: 1,
  classId: 8,
  canViewDetails: true,
};
const otherClassBusyBlock: VisibleSchedule = {
  id: null,
  classId: null,
  canViewDetails: false,
};
const anotherOwnVisibleSchedule: VisibleSchedule = {
  id: 2,
  classId: 9,
  canViewDetails: true,
};

describe('schedule visibility helpers', () => {
  it('keeps masked shared-room occupancy visible while filtering to one class', () => {
    expect(
      filterSchedulesForClass([ownSchedule, otherClassBusyBlock, anotherOwnVisibleSchedule], 8),
    ).toEqual([ownSchedule, otherClassBusyBlock]);
  });

  it('keeps a rental schedule with explicit detail access unmasked', () => {
    expect(isMaskedSchedule({ id: 3, classId: null, canViewDetails: true })).toBe(false);
  });

  it('treats nullable IDs as masked for responses without an explicit detail flag', () => {
    expect(isMaskedSchedule({ id: null, classId: null })).toBe(true);
    expect(isMaskedSchedule(ownSchedule)).toBe(false);
  });
});
