/*
 * @Author: WuWei
 * @Date: 2020-07-02 09:58:34
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2022-12-19 09:34:05
 * @Description: 报修service
 */

import 'package:app_package/app_package.dart';
import 'package:service_center_package/src/models/deal_person.dart';
import 'package:service_center_package/src/models/status.dart';
import 'package:service_center_package/src/models/inner_sort_list.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/repair_list.dart';
import '../repair_service.dart';

class OverdueRepairServiceImpl implements OverdueRepairService {
  static String _prefix = '/app/admin';

  @override
  Future<ResModel<PagingModel<RepairListModel>>> getRepairList(data) async {
    var res = await HttpUtil.instance.get(
      '$_prefix/repair',
      queryParameters: data,
    );
    return ResModel<PagingModel<RepairListModel>>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => PagingModel(
        json: v,
        to: (v) => v.toJson(),
        from: (v) => RepairListModel.fromJson(v),
      ),
    );
  }

  /// 报事报修状态枚举 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/20670
  Future<ResModel<List<TypeListModel>>> getTypeList() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/repairBusinessType',
    );

    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/repairSort/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(),
    );
  }

  /// 内部分类列表 http://yapi.wisdomcity.com.cn/project/16/interface/api/20844
  Future<ResModel<List<InnerSortListModel>>> getInnerSortList() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/repair/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(),
    );
  }
}
