/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2023-07-18 16:35:03
 * @LastEditTime : 2023-07-20 10:40:02
 * @Description  : Do not edit
 */

import 'package:app_package/app_package.dart';
import 'package:news_package/src/models/industry_news_detail.dart';
import 'package:news_package/src/models/industry_news_list.dart';
import 'package:news_package/src/service/industry_news_list.dart';

class IndustryNewsServiceImpl implements IndustryNewService {
  static String prefix = '/app/admin/platform';

  @override
  Future<ResModel<PagingModel<IndustryNewsListModel>>> getNewsList(data) async {
    var res = await HttpUtil.instance.get(
      '$prefix/news/industry',
      queryParameters: data,
    );

    return ResModel<PagingModel<IndustryNewsListModel>>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => PagingModel(
        json: v,
        to: (v) => v.toJson(),
        from: (v) => IndustryNewsListModel.fromJson(v),
      ),
    );
  }

  @override
  Future<ResModel<IndustryNewsDetailModel>> getNewsDetail(data) async {
    var res = await HttpUtil.instance.get(
      '$prefix/news/detail',
      queryParameters: data,
    );

    return ResModel<IndustryNewsDetailModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => IndustryNewsDetailModel.fromJson(v),
    );
  }

  noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);

  /// 首页资讯
  Future<ResModel<PagingModel<IndustryNewsListModel>>> getIndexNews(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/news/page',
      queryParameters: data,
    );

    return ResModel<PagingModel<IndustryNewsListModel>>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => PagingModel(
        json: v,
        to: (v) => v.toJson(),
        from: (v) => IndustryNewsListModel.fromJson(v),
      ),
    );
  }

  Future<ResModel<IndustryNewsDetailModel>> getNewsDetailV2(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/news/detail/v2/${data['id']}',
    );

    return ResModel<IndustryNewsDetailModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => IndustryNewsDetailModel.fromJson(v),
    );
  }
}
