/*
 * @Author: XianKaiQun
 * @Date: 2020-07-28 11:56:40
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-10-28 17:42:53
 * @Description: 
 */
import 'package:app_package/app_package.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:qrcode_package/src/impl/repair_service_impl.dart';
import 'package:qrcode_package/src/models/repair_plan.dart';

class PrivateRepairStore with ChangeNotifier {
  final BuildContext context, providerContext;
  late Map<String, dynamic> routingArgs;
  PrivateRepairStore(this.context, this.providerContext) {
    routingArgs = (ModalRoute.of(context)?.settings.arguments ??
            new Map<String, dynamic>()) as Map<String, dynamic>? ??
        {};
  }
  final communityGlobalStore = GetIt.I.get<CommunityGlobalStore>();

  ///当前小区
  CommunityModel? get currentCommunity => communityGlobalStore.data;

  ///巡检计划
  List<RepairPlanModel> pollingPlans = [];

  ///保养计划
  List<RepairPlanModel> repairPlans = [];

  ///路由到设备详情页
  route2detail(String? equipmentId) {
    Navigator.pushNamed(
      context,
      'qrcode/repair_detail',
      arguments: {
        'id': equipmentId,
      },
    );
  }

  ///巡检计划
  Future getPollingPlans() async {
    if (await communityGlobalStore.intent == false) {
      return Navigator.pop(context);
    }
    final res = await RepairServiceImpl.instance!.getPlans({
      'communityId': currentCommunity?.id,
      'type': 'pqc',
    });
    pollingPlans = res.data ?? [];
    notifyListeners();
  }

  ///保养计划
  Future getRepairPlans() async {
    if (await communityGlobalStore.intent == false) {
      return Navigator.pop(context);
    }
    final res = await RepairServiceImpl.instance!.getPlans({
      'communityId': currentCommunity?.id,
      'type': 'upkeep',
    });
    repairPlans = res.data ?? [];
    notifyListeners();
  }
}
