package nxm.sys.inc;

import nxm.sys.lib.Parser;
import nxm.sys.lib.Shell;

/** Defines the internal debug options.

    @author Jeff Schoen
 */
public interface Debug {
  /** Indicates that debugging messages should be turned on for I/O. */
  int IO=0x001;

  /** Indicates that debugging messages should be turned on for macros. */
  int MACRO=0x002;

  /** Indicates that debugging messages should be turned on for pipes. */
  int PIPES=0x004;

  /** Indicates that debugging messages should be turned on for graphics. */
  int GRAPHICS=0x008;

  /** Indicates that debugging messages should be turned on for results. */
  int RESULTS=0x010;

  /** Indicates that debugging messages should be turned on for primitives. */
  int PRIMITIVE=0x020;

  /** Indicates that debugging messages should be turned on for internals */
  int SHELL=0x040;

  /** Indicates that debugging messages should be turned on for arguments. */
  int ARGS=0x080;

  /** Indicates that stack traces should be included with error messages (where available).
      @see nxm.sys.lib.Midas#printStackTrace(CharSequence, Throwable)
   */
  int TRACE=0x100;

  /** Indicates that debugging messages should be turned on for deprecated functionality.
      @see nxm.sys.lib.Midas#deprecate(CharSequence)
   */
  int DEPRECATE=0x200;

  /** Indicates that when debugging messages are on for traces {@link #TRACE}, the trace should
      include source code where available. This has no effect is {@link #TRACE} is not enabled.
      @since NeXtMidas 2.7.1
      @see nxm.sys.lib.Midas#printStackTrace(CharSequence,Throwable)
   */
  int SUPERTRACE=0x400;

  /** The comma-separated list of debugging options ({@value}). */
  String debugList = "IO,Macro,Pipes,Graphics,Results,"
                                       + "Primitive,Shell,Args,Trace,"
                                       + "Deprecate,SuperTrace";

  /** Save current debug settings into GLOBAL debug settings: <br>
      1. Shell.getMidasContext() (to effect all future Midas contexts)
      2. ENV.DEBUG table (for save/load state)
      @param MR Results table
      @param debugMask debug mask to save into global debug settings
      @since NeXtMidas 3.1.2 (public for internal use in 3.5.2)
      @since NeXtMidas 3.9.2 moved here for project visibility in jdk modularity approach
   */
  @InternalUseOnly
  public static void saveGlobalDebugSettings (nxm.sys.lib.Results MR, final int debugMask) {
    // 1. save into global MidasContext
    Shell.getSharedMidasContext().setDebug(debugMask);
    // 2. put in the global environment table for save/loadState()
    MR.put("ENV.DEBUG", Parser.mask2s(Debug.debugList, debugMask), nxm.sys.lib.Table.FORCE);
  }

} // interface Debug