import type { MissionRuntimeState } from "./contracts";

const TERMINAL_ACQUISITION_STATES = new Set([
  "completed",
  "failed",
  "aborted",
  "interrupted",
]);

export const SPATIAL_SOURCE_SWITCH_BLOCKED_REASON =
  "Завершите текущий приём перед сменой источника.";

/**
 * An acquisition snapshot is blocking unless its state is explicitly known to
 * be terminal. Unknown future states therefore fail closed.
 */
export function isSpatialSourceSwitchBlocked(
  state: MissionRuntimeState | null | undefined,
): boolean {
  const acquisition = state?.acquisition;
  return Boolean(
    acquisition &&
      (acquisition.cleanupPending === true ||
        !TERMINAL_ACQUISITION_STATES.has(acquisition.state)),
  );
}
