package nxm.sys.lib;

import nxm.sys.inc.InternalUseOnly;
import nxm.sys.inc.LimitedFutureSupport;
import nxm.sys.inc.MidasColor;
import nxm.sys.inc.PlotFileNH;
import nxm.sys.libg.Layer;
import nxm.sys.libg.Layer1D;
import nxm.sys.libg.Layer2D;
import nxm.sys.libg.LayerMulti;
import nxm.sys.libg.LayerPoly;
import nxm.sys.libg.LayerT5;
import nxm.sys.libg.LayerXY;

/** ************  STANDARD VERSION ***********************
 *  Swapable Interface that allows libg, prim, int dependency to be
 *  easily removed for JDK 11 Modularity (smaller jar files) purposes
 *
 *  @author Jeanette McCall
 *  @since NextMidas 4.0.0
 */
interface DataFileModSwapInterface extends PlotFileNH {

  /** Get the default {@link Layer} on which this file is plotted.
   *  Removing libg dependencies from lib due to JDK 11+ Modularity. Since NeXtMidas 3.9.2
   *  See JDK_Modularity_User_Action_Required.xlxs for more details.
   */
  @LimitedFutureSupport("plot now uses a registry to find the appropriate getLayer method, rather than accessing a PlotFile instance method")
  @Override
  public default Layer getLayer () {
    return getLayer(0);
  }

  /** Special version of {@link #getLayer()} that is used internal to {@link Layer}.
      This is necessary since {@link DataFile} supports so many types and needs to
      know some of the PLOT options in order to determine which layer type to use.
      This version is for internal use only and may change without notice.
      @param plotType plot type
      @return layer
      @since NeXtMidas 3.3.2
      @deprecated Removing libg dependencies from lib due to JDK 11+ Modularity. Since NeXtMidas 3.9.1
   */
  @Deprecated
  @InternalUseOnly
  public default Layer getLayer (int plotType) {
    switch (getType()) {
      case 1998: return new LayerPoly(MidasColor.MAPLINE);
      case 1999: return new LayerPoly(MidasColor.MAPLINE);
    }

    boolean oneFrame   = (getSize() == 1) && !isStream();
    boolean isLinePlot = (plotType==T_LINE) || (plotType==T_POINT) || (plotType==T_DOT);

    switch (getTypeCodeClass()) {
      case 1:  return new Layer1D();
      case 2:  return (oneFrame||isLinePlot)? new Layer1D() : new Layer2D();
      case 3:  return ((findRec("ABSC")>=0||findRec("TIME")>=0))? new LayerXY() : new LayerMulti();
      case 6:  return ((findRec("ABSC")>=0||findRec("TIME")>=0))? new LayerXY() : new LayerMulti();
      case 5:  return new LayerT5();
      default: return null;
    }
  }

  public int findRec (String string);

  public int getTypeCodeClass ();

}
