import 'dart:io';

import 'package:base_app/common/common.dart';
import 'package:base_app/data/api/apis.dart';
import 'package:base_app/data/net/dio_util.dart';
import 'package:base_app/data/protocol/base_resp.dart';
import 'package:base_app/data/protocol/model.dart';
import 'package:base_app/models/models.dart';
import 'package:dio/dio.dart';

class ArticleRepository {
  // 文章列表
  Future<List<ArticleModel>> getArticleList(ArticleListReq req) async {
    BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
        .request<Map<String, dynamic>>(
            Method.get, AppApi.getPath(path: AppApi.article_list, resType: ''),
            data: req.toFormData());
    if (baseResp.code != Constant.status_success) {
      return new Future.error(baseResp.message);
    }
    List<ArticleModel> list;
    if (baseResp.data != null) {
      ArticleListResp articlelist = ArticleListResp.fromJson(baseResp.data);
      list = articlelist.datas?.map<ArticleModel>((value) {
        ArticleModel model = ArticleModel.fromJson(value);
        return model;
      })?.toList();
    }
    return list;
  }

  // 获取文章内容
  // Future<ArticleModel> getArticleInfo(String id) async {
  //   FormData params = FormData.from({'id': id});
  //   BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
  //       .request<Map<String, dynamic>>(
  //           Method.get, AppApi.getPath(path: AppApi.Article_info, resType: ''),
  //           data: params);
  //   if (baseResp.code != Constant.status_success) {
  //     return new Future.error(baseResp.message);
  //   }
  //   ArticleModel model;
  //   if (baseResp.data != null) {
  //     model = ArticleModel.fromJson(baseResp.data);
  //   }
  //   return model;
  // }
}
