/*
 * @Author: WuWei
 * @Date: 2020-07-21 15:22:12
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2022-12-15 17:15:21
 * @Description:
 */
import 'package:app_package/app_package.dart';
import 'package:service_center_package/src/models/deal_person.dart';
import 'package:service_center_package/src/models/inner_sort_list.dart';
import 'package:service_center_package/src/models/report_classify.dart';
import 'package:service_center_package/src/models/sort_list.dart';
import 'package:service_center_package/src/models/type_list.dart';
import 'package:service_center_package/src/models/report_list_model.dart';
import 'package:service_center_package/src/models/status.dart';
import '../report_service.dart';

class OverdueReportServiceImpl implements OverdueReportService {
  static String _prefix = '/app/admin';

  @override
  Future<ResModel<PagingModel<ReportListModel>>> getReportList(data) async {
    var res = await HttpUtil.instance.get(
      '$_prefix/report',
      queryParameters: data,
    );

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

  /// 报事分类
  /// http://yapi.wisdomcity.com.cn/project/16/interface/api/1977
  Future<ResModel<List<ReportClassifyModel>>> getDealClassify(data) async {
    var res = await HttpUtil.instance.get(
      '$_prefix/report/sort',
      queryParameters: data,
    );

    return ResModel<List<ReportClassifyModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<ReportClassifyModel>((f) => ReportClassifyModel.fromJson(f))
          .toList(),
    );
  }

  /// 内部分类列表 http://yapi.wisdomcity.com.cn/project/16/interface/api/20846
  Future<ResModel<List<InnerSortListModel>>> getInnerSortList() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/report/internalSort',
    );
    return ResModel<List<InnerSortListModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<InnerSortListModel>((f) => InnerSortListModel.fromJson(f))
          .toList(),
    );
  }

  ///报事分类
  Future<ResModel<List<StatusModel>>> getReportSortList() async {
    final res = await HttpUtil.instance.get('$_prefix/reportSort/name');
    return ResModel<List<StatusModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<StatusModel>(
            (f) => StatusModel(code: f['id'], name: f['sortName']),
          )
          .toList(),
    );
  }

  ///报事业务类型
  Future<ResModel<List<StatusModel>>> getBusinessStatus(type) async {
    final res = await HttpUtil.instance.get(
      '$_prefix/serviceWorkBench/enu',
      queryParameters: {
        'type': type,
      },
    );
    return ResModel<List<StatusModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<StatusModel>(
            (f) => StatusModel.fromJson(f),
          )
          .toList(),
    );
  }

  /// 报事报修状态枚举 http://yapi.wisdomcity.com.cn/project/40/interface/api/19049
  Future<ResModel<List<StatusModel>>> getStatusEnum() async {
    var res = await HttpUtil.instance.get(
      '$_prefix/commonEnum/app/ReportOrRepairStatusEnum',
    );

    return ResModel<List<StatusModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<StatusModel>((f) => StatusModel.fromJson(f)).toList(),
    );
  }

  /// 处理人列表
  Future<ResModel<List<DealPeasonModel>>> getDealPerson(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/employee/report/acceptPersons',
      queryParameters: data,
    );

    return ResModel<List<DealPeasonModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<DealPeasonModel>((f) => DealPeasonModel.fromJson(f))
          .toList(),
    );
  }

  /// 类别列表 http://yapi.wisdomcity.com.cn/project/16/interface/api/20672
  Future<ResModel<List<TypeListModel>>> getTypeList() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/reportBusinessType',
    );

    return ResModel<List<TypeListModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<TypeListModel>((f) => TypeListModel.fromJson(f))
          .toList(),
    );
  }

  /// 分类列表 http://yapi.wisdomcity.com.cn/project/16/interface/api/20670
  Future<ResModel<List<SortListModel>>> getSortList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/reportSort/name',
      queryParameters: data,
    );

    return ResModel<List<SortListModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<SortListModel>((f) => SortListModel.fromJson(f))
          .toList(),
    );
  }
}
