import 'package:fis_jsonrpc/services/contractRecord.m.dart';
import 'package:get/get.dart';
import 'package:vitalapp/architecture/defines.dart';
import 'package:vitalapp/managers/interfaces/contract.dart';

import 'state.dart';

class ContractRecordsHtmlController extends FControllerBase {
  final state = ContractRecordsHtmlState();
  final _contractManager = Get.find<IContractManager>();
  late String contractCode;
  @override
  void onReady() {
    super.onReady();
    _initData();
    getContractRecordDetailAsync(contractCode);
  }

  _initData() {
    update(["contract_records"]);
    final p = Get.parameters;
    contractCode = p['contractCode'] ?? "";
  }

  Future<void> getContractRecordDetailAsync(String patientCode) async {
    busy = true;
    var result =
        await _contractManager.getContractRecordDetailAsync(patientCode);
    if (result != null) {
      state.contractRecordDTO = result;
    }
    busy = false;
  }

  Future<bool> updateContractRecordStateAsync(String reason) async {
    var result = await _contractManager.updateContractRecordStateAsync(
        contractCode, ContractStateEnum.Cancelled, reason);
    return result;
  }

  ///续约
  Future<String> renewalContractRecordAsync() async {
    var result =
        await _contractManager.renewalContractRecordAsync(contractCode);
    return result;
  }
}
