import 'package:zhiying_comm/zhiying_comm.dart';

class SearchRepository {
  List<Map<String, dynamic>> _pageData = [];

  /// 获取网络数据
  Future<List<Map<String, dynamic>>> fetchInit(final Map<String, dynamic> model) async {
    var result = await NetUtil.post('/api/v1/mod/pub.flutter.search_index', method: NetMethod.GET, cache: true);
    if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result)) {
      try {
        _pageData = List.from(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]['mod_list']);
        return _pageData;
      } catch (e) {
        Logger.error(e.toString());
      }
    }
    return null;
  }

  /// 获取缓存数据
  Future<List<Map<String, dynamic>>> fetchCachedData(final Map<String, dynamic> model) async{
    var result = await NetUtil.getRequestCachedData('/api/v1/mod/pub.flutter.search_index');
    try {
      if (!EmptyUtil.isEmpty(result)) {
        return List.from(result['mod_list']);
      }
    }catch(e){}
    return null;
  }

  /// 搜索的方法
  Future<void> fetchSearchSubmit(final String model) async {
    var result = await NetUtil.post('');
  }
}
