"use strict";

const { Service } = require("ee-core");
const Cross = require("ee-core/cross");
const Log = require("ee-core/log");
const Ps = require("ee-core/ps");
const path = require("path");
const Is = require("ee-core/utils/is");

/**
 * cross（service层为单例）
 * @class
 */
class CrossService extends Service {
  constructor(ctx) {
    super(ctx);
  }
  /**
   * create python service
   * In the default configuration, services can be started with applications.
   * Developers can turn off the configuration and create it manually.
   */
  async createPythonServer() {
    // method 1: Use the default Settings
    //const entity = await Cross.run(serviceName);

    // method 2: Use custom configuration
    const serviceName = "python";
    const opt = {
      name: "pyapp",
      cmd: path.join(Ps.getExtraResourcesDir(), "py", "pyapp"),
      directory: path.join(Ps.getExtraResourcesDir(), "py"),
      args: ["--port=7074"],
      windowsExtname: true,
      appExit: true,
    };
    const entity = await Cross.run(serviceName, opt);
    Log.info("server name:", entity.name);
    Log.info("server config:", entity.config);
    Log.info("server url:", entity.getUrl());

    return;
  }
}

CrossService.toString = () => "[class CrossService]";
module.exports = CrossService;
