/*
 * @Author: XianKaiQun
 * @Date: 2020-08-17 08:33:23
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-11-07 15:17:24
 * @Description: 
 */
import 'package:app_package/app_package.dart';
import 'package:receipt_package/src/models/acquire_detail.dart';
import 'package:receipt_package/src/models/advance.dart';
import 'package:receipt_package/src/models/arrears_fee.dart';
import 'package:receipt_package/src/models/code_name.dart';
import 'package:receipt_package/src/models/community_config.dart';
import 'package:receipt_package/src/models/deposit_asset_detail.dart';
import 'package:receipt_package/src/models/deposit_detail.dart';
import 'package:receipt_package/src/models/pay_type.dart';
import 'package:receipt_package/src/models/payer.dart';
import 'package:receipt_package/src/models/search_item.dart';
import 'package:receipt_package/src/services/receipt_service.dart';
import 'package:receipt_package/src/view_models/success.dart';

import '../models/asset_list.dart';
import '../models/deposite_charge_item.dart';
import '../models/prefee_charge_item.dart';
import '../models/prefee_general.dart';

class ReceiptServiceImpl implements ReceiptService {
  static String _prefix = '/app/admin/assetBill';
  @override
  Future<ResModel<PagingModel<SearchItemModel>>> getCarSearchList(data) async {
    var res = await HttpUtil.instance.get(
      'app/admin/assets/v1/car/search/card_no',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<PagingModel<SearchItemModel>>> getHouseSearchList(
      data) async {
    var res = await HttpUtil.instance.get(
      'app/admin/assets/v1/house/search/room_no',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<PagingModel<SearchItemModel>>> getParkSearchList(data) async {
    var res = await HttpUtil.instance.get(
      'app/admin/assets/v1/parking_space/search/code',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<AcquireDetailModel>> getAcquireDetail(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assetBill/v1/acquire/detail',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<List<DepositDetailModel>?>> getCarDepositDetail(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/prepay/v1/car/detail',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<List<DepositDetailModel>?>> getHouseDepositDetail(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/prepay/v1/house/detail',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<List<DepositDetailModel>?>> getPackDepositDetail(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/prepay/v1/parking_space/detail',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<DepositAssetDetailModel>> getPackDepositAssetDetail(
      data) async {
    var res = await HttpUtil.instance.get(
      'app/admin/deposite/v1/asset/detail',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<List<PayerModel>?>> getPayerList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/v1/payer',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<List<CodeNameModel>?>> getPayTypeList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/pay/v1/paytypes',
      queryParameters: data,
    );
    res.data['data'] = res.data['data']['offLine'];
    return ResModel<List<CodeNameModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<CodeNameModel>((f) => CodeNameModel.fromJson(f))
          .toList(),
    );
  }

  @override
  Future<ResModel<List<AdvanceModel>?>> getChargeItem(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/chargeStandard/v1/chargeItem',
      queryParameters: data,
    );
    return ResModel<List<AdvanceModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<AdvanceModel>((f) => AdvanceModel.fromJson(f)).toList(),
    );
  }

  @override
  Future<ResModel<List<AdvanceModel>?>> getPrePayChoiceAsset(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/v1/prePayChoiceAsset',
      queryParameters: data,
    );
    return ResModel<List<AdvanceModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<AdvanceModel>((f) => AdvanceModel.fromJson(f)).toList(),
    );
  }

/**
 * 手机录单v2
 * http://yapi.wisdomcity.com.cn/project/40/interface/api/22593
 */
  @override
  Future<ResModel<Map<String, dynamic>?>> postAcquire(data) async {
    var res = await HttpUtil.instance.post(
      '/app/admin/assetBill/mobile/acquire2',
      data: data,
    );

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

  @override
  Future<ResModel<SuccessModel>> getSuccess(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assetBill/v1/acquire/success',
      queryParameters: data,
    );

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

  ///统计小区欠费
  static Future<ResModel<num>> getArrearsFeeTotal(data) async {
    var res = await HttpUtil.instance.get(
      '$_prefix/v1/arrearsFeeStatisticsCommunityId',
      queryParameters: data,
    );

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

  ///根据小区统计欠费户数
  static Future<ResModel<List<ArrearsFeeModel>>> getArrearsFeeList(data) async {
    var res = await HttpUtil.instance.get(
      '$_prefix//v1/arrearsFeeStatistics',
      queryParameters: data,
    );

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

  /// 手机收单
  /// [http://yapi.wisdomcity.com.cn/project/40/interface/api/20042 ]
  static Future<ResModel<List<PayTypeModel>>> getPayTypeBankList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/offLinePayType/community',
      queryParameters: data,
    );

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

  /// 小区配置信息
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20037
  static Future<ResModel<CommunityConfigModel>> getCommunityConf(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/communityConfiguration/${data['communityId']}',
    );

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

  /// 根据资产id和列表选择获取关联的业主信息和关联的资产信息
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/22588
  static Future<ResModel<List<AssetListModel>>> getAssetListByAssetId(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/getOwnerAndRelationAsset',
      queryParameters: data,
    );
    return ResModel<List<AssetListModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<AssetListModel>((f) => AssetListModel.fromJson(f))
          .toList(),
    );
  }

  static Future<ResModel<PrefeeGeneralModel>> getGeneralPrefee(data) async {
    var res = await HttpUtil.instance.get(
      '/app/hgj/prePay/general/pay',
      queryParameters: data,
    );

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

  static Future<ResModel<List<PrefeeChargeItemModel>>> getPrefeeChargeItemList(
      data) async {
    var res = await HttpUtil.instance.get(
      'app/hgj/chargeStandard',
      queryParameters: data,
    );

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

  /// 押金列表
  /// http://yapi.wisdomcity.com.cn/project/13/interface/api/22143
  static Future<ResModel<List<DepositeChargeItemModel>>>
      getDepositeChargeItemList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/deposite/type',
      queryParameters: data,
    );
    return ResModel<List<DepositeChargeItemModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<DepositeChargeItemModel>(
              (f) => DepositeChargeItemModel.fromJson(f))
          .toList(),
    );
  }
}
