import { describe, expect, it } from 'vitest';
import {
  canManageSafetyProtocols,
  isSafetyDraftValid,
} from '@/business/safety-protocols/selectors';
import type { SafetyProtocolDraft } from '@/business/safety-protocols/types';

const validDraft: SafetyProtocolDraft = {
  title: 'Fire Drill',
  tag: 'fire',
  steps: ['', 'Walk to assembly point'],
  autismConsiderations: [''],
};

describe('safety protocol selectors', () => {
  it('shares the policy-document management grant', () => {
    expect(canManageSafetyProtocols('owner')).toBe(true);
    expect(canManageSafetyProtocols('superintendent')).toBe(true);
    expect(canManageSafetyProtocols('director')).toBe(true);
    expect(canManageSafetyProtocols('office_manager')).toBe(true);
    expect(canManageSafetyProtocols('teacher')).toBe(false);
    expect(canManageSafetyProtocols('support_staff')).toBe(false);
    expect(canManageSafetyProtocols('student')).toBe(false);
  });

  it('requires a title and at least one non-empty step', () => {
    expect(isSafetyDraftValid(validDraft)).toBe(true);
    expect(isSafetyDraftValid({ ...validDraft, title: '   ' })).toBe(false);
    expect(isSafetyDraftValid({ ...validDraft, steps: ['', '  '] })).toBe(false);
  });
});
