/*
 * @Author: XianKaiQun
 * @Date: 2020-07-15 11:27:10
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-10-28 17:43:33
 * @Description: 
 */
import 'package:app_package/app_package.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:receipt_package/src/impl/receipt_service_impl.dart';
import 'package:receipt_package/src/models/deposit_detail.dart';

class PrivateDepositDetailStore with ChangeNotifier {
  final BuildContext context, providerContext;
  final Map<String, dynamic> routingArgs;
  PrivateDepositDetailStore(this.context, this.providerContext)
      : routingArgs = (ModalRoute.of(context)?.settings.arguments ??
                new Map<String, dynamic>()) as Map<String, dynamic>? ??
            {};
  String? get type => routingArgs['type'];
  String? get id => routingArgs['id'];
  final communityGlobalStore = GetIt.I.get<CommunityGlobalStore>();

  String? get communityId => communityGlobalStore.data.id;

  List<DepositDetailModel>? list;

  Future getList() async {
    ResModel<List<DepositDetailModel>?>? res;
    switch (type) {
      case 'house':
        res = await ReceiptServiceImpl().getHouseDepositDetail({
          'communityId': communityId,
          'houseId': id,
        });
        break;
      case 'car':
        res = await ReceiptServiceImpl().getCarDepositDetail({
          'communityId': communityId,
          'carId': id,
        });
        break;
      case 'parkingSpace':
        res = await ReceiptServiceImpl().getPackDepositDetail({
          'communityId': communityId,
          'parkingSpaceId': id,
        });
        break;
    }
    list = res?.data ?? [];
    notifyListeners();
  }
}
