package nxm.sys.inc;

import nxm.sys.lib.CsvFile;
import nxm.sys.lib.DataFile;
import nxm.sys.lib.GeoJSONFile;
import nxm.sys.lib.ImageFile;
import nxm.sys.lib.KmlFile;
import nxm.sys.lib.ShapeFile;
import nxm.sys.lib.Shell;
import nxm.sys.libg.Layer;
import nxm.sys.libg.LayerGeoJSON;
import nxm.sys.libg.LayerImage;
import nxm.sys.libg.LayerKML;
import nxm.sys.libg.LayerMulti;
import nxm.sys.libg.LayerShape;
import nxm.sys.libg.LayerUtil;

/** ** STANDARD VERSION **

    @author  Jeanette McCall
 */
interface PlotFileModSwap {

  /** Get the default {@link Layer} on which this file is plotted.<br>
      New PlotFile to getLayer() registry should be used instead of overriding this method.
      We are removing libg dependencies from lib to transition to JDK module support
      @return The default layer to use, or <code>null</code> to let <code>PLOT</code> decide.
   */
  default Layer getLayer () {
    if (this instanceof DataFile) {
      return getLayer(0);
    }
    return getLayerByClass();
  }

  /** 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) {
    if (this instanceof DataFile) {
      return LayerUtil.getDataFileLayer((DataFile)this, plotType);
    }
    else return getLayerByClass();
  }

   /** Get the corresponding Layer instance
    *
    *  @return The corresponding Layer instance
    *  @since NeXtMidas 4.3.1
    */
  default Layer getLayerByClass () {
    if (this instanceof CsvFile) {
      return new LayerMulti();
    }
    else if (this instanceof GeoJSONFile) {
      return new LayerGeoJSON();
    }
    else if (this instanceof ImageFile) {
      return new LayerImage();
    }
    else if (this instanceof KmlFile) {
      return new LayerKML();
    }
    else if (this instanceof ShapeFile) {
      return new LayerShape();
    }
    Shell.getMidasContext().warning(this+" should have entry added to New PlotFile to getLayer() registry. No getLayer() method present ");
    return null;
  }
}
