import tencentFlashTaskASR from "./sp/tencent/flashFileTencent";
import aliyunFlashTaskASR from "./sp/aliyun/flashFileAliyun";
import huaweiFlashTaskASR from "./sp/huawei/flashFileHuawei";

class FlashTaskASRFactory {
  constructor(sp) {
    this.policy = sp || "baidu";
  }

  static getInstance(policy, options) {
    switch (policy) {
      // case "baidu":
      //   return new baiduFlashTaskASR(options);
      case "tencent":
        return new tencentFlashTaskASR(options);
      case "ali":
        return new aliyunFlashTaskASR(options);
      case "huawei":
        return new huaweiFlashTaskASR(options);
      default:
        return new tencentFlashTaskASR(options);
    }
  }
  static resAnalysis(policy,res) {
    var result = {
      sp:policy,
      message: "success",
      result: "",
      statusCode:200,
      error: {}
    };
    // console.log("res:",res);
    if (res==null||res.status != 200) {
      result.message="error";
      result.error = res.statusText;
      result.statusCode=500||res.status;
      return result;
    }
    switch (policy) {
      // case "baidu":
      //   {
      //     var body = res.data;
      //     if (body.err_no == 0) {
      //       result.message ="success";
      //       result.result = body.result;
      //       result.statusCode=200;
      //     } else {
      //       result.message = "error";
      //       result.error = body.err_msg;
      //       result.statusCode=body.err_no;
      //     }
      //     return result;
      //   }
      case "tencent":
       {
        var body = res;
          result.message ="success";
          result.result = body.Result;
          result.statusCode=200;
        return result;
       }
      case "ali":
        {
          var body = res.data;
          if (body.status == 20000000) {
            result.message ="success";
            result.result = body.result;
            result.statusCode=200;
          } else {
            result.message = body.message;
            result.error = body.message;
            result.statusCode=501;
          }
          return result;
        }
      case "huawei":
        {
          var body = res.data;
            result.message ="success";
            result.result = body.result.text;
            result.statusCode=200;
          return result;
        }
      default:
        return result;
    }

  }
}

export default FlashTaskASRFactory;
