/*
 * @Author: XianKaiQun
 * @Date: 2020-04-22 10:57:24
 * @LastEditors: wuwei
 * @LastEditTime: 2024-01-31 14:59:00
 * @Descripttion: 
 */
import 'package:app_package/app_package.dart';
import 'package:app_package/src/models/fee_statistics.dart';
import 'package:bill_package/src/models/arrears_fee.dart';
import 'package:bill_package/src/models/house_bill_details.dart';
import 'package:bill_package/src/models/house_bills.dart';
import 'package:bill_package/src/models/search_item.dart';

import '../models/asset_list.dart';
import '../models/cascade.dart';
import '../models/deposite_charge_item.dart';
import '../models/deposite_detail.dart';
import '../models/fee_total_count.dart';
import '../models/fee_type.dart';
import '../models/liquidated_damages.dart';
import '../models/owe_fee_count.dart';
import '../models/owe_fee_info.dart';
import '../models/owe_fee_month_list.dart';
import '../models/payer.dart';
import '../models/prefee_charge_item.dart';
import '../models/prefee_detail.dart';
import '../models/prefee_general.dart';

class AssetBillApi {
  static String _prefix = '/app/admin/assetBill';

  /// 收费卡片
  /// http://yapi.wisdomcity.com.cn/project/40/interface/api/20988
  static Future<ResModel<FeeStatisticsModel>> getFeeStatistics(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/hgj/pay/statistics/collectionRate',
      queryParameters: data,
    );

    return ResModel<FeeStatisticsModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => FeeStatisticsModel.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(),
    );
  }

  ///收费管理列表
  static Future<ResModel<PagingModel<HouseBillsModel>>> getHouseBillsList(
      data) async {
    var res = await HttpUtil.instance.get(
      '$_prefix/houseBills',
      queryParameters: data,
    );

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

  ///收费管理列表详情
  static Future<ResModel<HouseBillDetailsModel>> getHouseBillsDetail(
      data) async {
    var res = await HttpUtil.instance.get(
      '$_prefix/houseBillDetails',
      queryParameters: data,
    );

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

  /// 使用与绘服务一致的账单明细 2023-10-24
  /// 根据资产id和账期查询资产账单
  /// http://yapi.wisdomcity.com.cn/project/13/interface/api/22468
  static Future<ResModel<OweFeeInfoModel>> getFeeListByMonth(data) async {
    var res = await HttpUtil.instance.get(
      '/app/hgj/assetBill/info',
      queryParameters: data,
    );

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

  /// 查询欠费统计
  /// 使用与绘服务一致的确认缴费页面 2023-10-25
  /// http://yapi.wisdomcity.com.cn/project/13/interface/api/22483
  static Future<ResModel<OweFeeCountModel>> getOweFeeCount(data) async {
    var res = await HttpUtil.instance.get(
      '/app/hgj/assetBill/countForPay',
      queryParameters: data,
    );

    return ResModel<OweFeeCountModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => OweFeeCountModel.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<List<FeeTypeModel>?>> getChargeItemList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/chargeStandard',
      queryParameters: data,
    );
    return ResModel<List<FeeTypeModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<FeeTypeModel>((f) => FeeTypeModel.fromJson(f)).toList(),
    );
  }

  /// 房屋搜索
  static 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),
      ),
    );
  }

  ///车辆搜索
  static 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),
      ),
    );
  }

  /// 车位搜索
  static 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),
      ),
    );
  }

  /// 住户搜索
  static Future<ResModel<PagingModel<ResidentItemModel>>> getResidentSearchList(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/search/v1/resident',
      queryParameters: data,
    );

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

  /// 押金明细
  /// http://yapi.wisdomcity.com.cn/project/13/interface/api/22418
  /// /app/deposite/balance/detail
  static Future<ResModel<DepositeDetailModel>> getDepositeFeeDetail(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/deposite/balance/detail',
      queryParameters: data,
    );

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

  /// 预存款明细
  /// http://yapi.wisdomcity.com.cn/project/13/interface/api/19957
  static Future<ResModel<PrefeeDetailModel>> getPreFeeDetail(data) async {
    var res = await HttpUtil.instance.get(
      '/app/hgj/prePay/detailV3',
      queryParameters: data,
    );

    return ResModel<PrefeeDetailModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => PrefeeDetailModel.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(),
    );
  }

  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<int>> postUrgePay(data) async {
    var res = await HttpUtil.instance.post(
      '/app/admin/hgj/assetBill/arrears/notice/record',
      data: data,
    );

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

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

  ///根据房屋id统计（欠费金额、预存余额、押金余额、违约金金额）
  ///http://yapi.wisdomcity.com.cn/project/13/interface/api/22428
  ///
  static Future<ResModel<TotalCountModel>> getFeeTotalCount(data) async {
    var res = await HttpUtil.instance.get(
      '/app/hgj/assetBill/countAmountByHouseId',
      queryParameters: data,
    );

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

  /// 查看违约金明细
  /// http://yapi.wisdomcity.com.cn/project/13/interface/api/22123
  static Future<ResModel<LiquidatedDamagesModel>> getLiquidatedDamages(
      billId) async {
    var res = await HttpUtil.instance.get(
      '/app/hgj/assetBill/liquidatedDamages/bill/byBillId/${billId}',
    );

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

  /// 获取欠费账期
  /// http://yapi.wisdomcity.com.cn/project/13/interface/api/22783
  static Future<ResModel<List>> getOweFeeMonthList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/hgj/assetBill/arrearsChargeYearMonths2',
      queryParameters: data,
    );

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

  ///楼栋列表
  Future<ResModel<List<CascadeModel>?>> getBuildInfo(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/getBuildInfo',
      queryParameters: data,
    );
    return ResModel<List<CascadeModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<CascadeModel>((f) => CascadeModel.fromJson(f)).toList(),
    );
  }

  ///单元列表
  Future<ResModel<List<CascadeModel>?>> getUnitInfo(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/getUnitInfo',
      queryParameters: data,
    );
    return ResModel<List<CascadeModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<CascadeModel>((f) => CascadeModel.fromJson(f)).toList(),
    );
  }

  ///楼层列表
  Future<ResModel<List<CascadeModel>?>> getFloorInfo(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/assets/getFloorInfo',
      queryParameters: data,
    );
    return ResModel<List<CascadeModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<CascadeModel>((f) => CascadeModel.fromJson(f)).toList(),
    );
  }

  // Future<ResModel<List<CascadeModel>?>> getHouseInfo(data) async {
  //   var res = await HttpUtil.instance.get(
  //     '/app/admin/assets/getHouseInfo',
  //     queryParameters: data,
  //   );
  //   return ResModel<List<CascadeModel>?>(
  //     json: res.data,
  //     to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
  //     from: (v) =>
  //         (v ?? []).map<CascadeModel>((f) => CascadeModel.fromJson(f)).toList(),
  //   );
  // }
  /// 房屋列表
  /// http://yapi.wisdomcity.com.cn/project/13/interface/api/199
  /// 2024.01.31 使用与绘服务一致的接口
  Future<ResModel<List<CascadeModel>?>> getHouseInfo(data) async {
    var res = await HttpUtil.instance.get(
      '/app/platform/assetBind/getHouseInfo',
      queryParameters: data,
    );
    return ResModel<List<CascadeModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<CascadeModel>((f) => CascadeModel.fromJson(f)).toList(),
    );
  }

  ///http://yapi.wisdomcity.com.cn/project/40/interface/api/23708
  ///收银台-欠费账单列表-hgj
  static Future<ResModel<List<OweFeeMonthListModel>>> getOweFeeListByMonth(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/hgj/assetBill/arrears/bill/list',
      queryParameters: data,
    );

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