import 'package:zhiying_base_widget/pages/search_think_page/model/search_think_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class SearchThinkRepository {


  // 商品电商渠道类型，默认为淘宝
  String type = 'taobao';

  /// 关键字改变
  Future<List<SearchThinkModel>> fetchkeyWordsChange(String keywrods) async {
    if (!EmptyUtil.isEmpty(keywrods)) {
      var result = await NetUtil.post('/api/v1/s/t/$keywrods', method: NetMethod.GET);
      try {
        if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
          List<String> data  = List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
          List<SearchThinkModel> newDatas = [];
          data.forEach((item){
            newDatas.add(SearchThinkModel(type: type, keywords: item));
          });
          return newDatas;
        }
      } catch (e) {
        Logger.error(e.toString());
      }
    }
    return null;
  }

  /// 修改渠道类型
  void changeType(String newType){
    this.type = newType;
    print('change type = $type');
  }
}
