import type { UserRole } from '@/shared/types/app';
import { canManagePolicies } from '@/business/policies/selectors';
import type { SafetyProtocolDraft } from '@/business/safety-protocols/types';

/**
 * Safety protocols are `policy_documents`, so authoring shares the policy
 * management grant (`CREATE/UPDATE/DELETE_POLICY_DOCUMENTS`). The backend stays
 * the source of truth; this only gates the management UI affordances.
 */
export function canManageSafetyProtocols(userRole: UserRole): boolean {
  return canManagePolicies(userRole);
}

/** A protocol needs a title and at least one non-empty procedure step. */
export function isSafetyDraftValid(draft: SafetyProtocolDraft): boolean {
  return Boolean(draft.title.trim() && draft.steps.some((step) => step.trim()));
}
