import baiduASR from "./sp/baidu/baidu";
import tencentASR from "./sp/tencent/tencent";
import aliyunASR from "./sp/aliyun/aliyun";
import huaweiASR from "./sp/huawei/huawei";

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

  static getInstance(policy, options) {
    switch (policy) {
      case "baidu":
        return new baiduASR(options);
      case "tencent":
        return new tencentASR(options);
      case "ali":
        return new aliyunASR(options);
      case "huawei":
        return new huaweiASR(options);
      default:
        return new tencentASR(options);
    }
  }
  static resAnalysis(res, policy) {
    var result = {
      message: "success",
      start_time: 0,
      end_time: 0,
      result: "",
      word_list: []
    };
    // console.log("++++++++++++++++++++",res);
    switch (policy) {
      case "baidu":
        result.start_time = res.start_time;
        result.end_time = res.end_time;
        result.result = {text:res.result};
        return result;
      case "tencent":
        result.start_time = res.result.start_time;
        result.end_time = res.result.end_time;
        result.result = {text:res.result.voice_text_str};
        result.word_list = res.result.word_list;
        return result;
      case "ali":
        result.start_time = res.payload.begin_time;
        result.end_time = res.payload.begin_time;
        result.result = {text:res.payload.result};
        result.word_list = res.payload.stash_result.words;
        return result;
      case "huawei":
        result.start_time = res.segments[0].start_time;
        result.end_time = res.segments[0].end_time;
        result.result = {text:res.segments[0].result.text};
        result.word_list = res.segments[0].result.word_info;
        return result;
      default:
        return result;
    }

  }
}

export default ASRFactory;
