/*
 * @Author: XianKaiQun
 * @Date: 2020-09-02 11:01:31
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2022-10-14 14:54:21
 * @Description: 
 */
import 'package:app_package/app_package.dart';
import 'package:service_package/src/models/cascade_house.dart';
import 'package:service_package/src/models/deal_person.dart';
import 'package:service_package/src/models/detail.dart';
import 'package:service_package/src/models/enum.dart';
import 'package:service_package/src/models/inner_sort_list.dart';
import 'package:service_package/src/models/qrcode.dart';
import 'package:service_package/src/models/sort_list.dart';
import 'package:service_package/src/models/staff.dart';
import 'package:service_package/src/models/type_list.dart';

class RequestApi {
  ///获取楼栋
  Future<ResModel<List<CascadeHouseModel>?>> getBuildInfo(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/getBuildInfo',
      queryParameters: data,
    );

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

  ///获取单元
  Future<ResModel<List<CascadeHouseModel>?>> getUnitInfo(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/getUnitInfo',
      queryParameters: data,
    );

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

  ///获取楼层
  Future<ResModel<List<CascadeHouseModel>?>> getFloorInfo(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/getFloorInfo',
      queryParameters: data,
    );

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

  ///获取房屋
  Future<ResModel<List<CascadeHouseModel>?>> getHouseInfo(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/getHouseInfo',
      queryParameters: data,
    );

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

  ///获取枚举
  Future<ResModel<List<EnumModel>?>> getEnum(String type) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/serviceWorkBench/enu',
      queryParameters: {
        'type': type,
      },
    );

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

  ///报事分类
  Future<ResModel<List<EnumModel>?>> getReportList() async {
    var res = await HttpUtil.instance.get('/app/admin/report/sort');
    return ResModel<List<EnumModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<EnumModel>(
            (f) => EnumModel(code: f['id'], name: f['sortName']),
          )
          .toList(),
    );
  }

  ///受理人列表
  Future<ResModel<List<StaffModel>?>> getStaffList(String? communityId) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/report/getAcceptEmployees',
      queryParameters: {'communityId': communityId},
    );
    return ResModel<List<StaffModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<StaffModel>(
            (f) => StaffModel.fromJson(f),
          )
          .toList(),
    );
  }

  ///新增报事
  Future<ResModel<String?>> postReport(data) async {
    var res = await HttpUtil.instance.post(
      '/app/admin/serviceWorkBench/report/v2',
      data: data,
    );

    return ResModel<String?>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }

  ///新增报修
  Future<ResModel<String?>> postRepair(data) async {
    var res = await HttpUtil.instance.post(
      '/app/admin/serviceWorkBench/repair/v2',
      data: data,
    );

    return ResModel<String?>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }

  ///报修二维码
  Future<ResModel<QrcodeModel>> getRepairQrCode(String? id) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/serviceWorkBench/repair/qrCode',
      queryParameters: {'id': id},
    );

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

  ///报事二维码
  Future<ResModel<QrcodeModel>> getReportQrCode(String? id) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/serviceWorkBench/report/qrCode',
      queryParameters: {'id': id},
    );

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

  ///报修详情
  Future<ResModel<DetailModel>> getRepairDetail(String? id) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/serviceWorkBench/repair/detail',
      queryParameters: {'id': id},
    );

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

  ///报事详情
  Future<ResModel<DetailModel>> getReportDetail(String? id) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/serviceWorkBench/report/detail',
      queryParameters: {'id': id},
    );

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

  /// 类别列表 http://yapi.wisdomcity.com.cn/project/16/interface/api/20672
  Future<ResModel<List<TypeListModel>>> getReportTypeList() 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>>> getReportSortList(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(),
    );
  }

  /// 类别列表 http://yapi.wisdomcity.com.cn/project/16/interface/api/20670
  Future<ResModel<List<TypeListModel>>> getRepairTypeList() 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>>> getRepairSortList(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/20846
  Future<ResModel<List<InnerSortListModel>>> getReportInnerSortList() 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(),
    );
  }

  /// 报修内部分类列表 http://yapi.wisdomcity.com.cn/project/16/interface/api/20846
  Future<ResModel<List<InnerSortListModel>>> getRepairInnerSortList() 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(),
    );
  }

  /// 处理人列表
  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(),
    );
  }
}
