
/**
 * 说明：
 * * 不同服务器的请求模块。
 */

import ApiCofig from "@/common/config/ApiCofig";
import { isDev } from "../common/config/AppCofig";
import { appendGetUrlParams } from "@imengyu/imengyu-utils";
import { BaseAppServerRequestModule } from "./BaseAppServerRequestModule";
import type { DataModel } from "@imengyu/js-request-transform";


/**
 * 主应用服务请求模块
 */
export class AppServerRequestModule<T extends DataModel> extends BaseAppServerRequestModule<T> {
  constructor() {
    super(isDev ? ApiCofig.server.Dev : ApiCofig.server.Prod);
  }
}

/**
 * 地图服务请求模块
 */
export class MapServerRequestModule<T extends DataModel> extends BaseAppServerRequestModule<T> {
  constructor() {
    super('https://restapi.amap.com');
    this.config.requestInterceptor = (url, req) => {
      url = appendGetUrlParams(url, 'key', ApiCofig.amapServerKey);
      return { newUrl: url, newReq: req };
    };
  }
}