import 'package:ef/ef.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:vbvs_app/controller/mh_controller/apply_repair_controller.dart';
import 'package:vbvs_app/controller/mh_controller/repair_process.dart';

part 'repair_info_controller.g.dart';

@JsonSerializable()
class RepairInfoModel {
  String? id; //记录id
  DateTime? create_time; //提交时间
  String? status; //状态
  String? desc; //描述
  int? record_id; //归属记录id

  List<RepairProcessModel> repairProcessList = []; //审核流程
  String? device_name;
  ApplyRepairModel? applyRepairModel;

  RepairInfoModel();

  static RepairInfoModel fromJson(Map<String, dynamic> json) =>
      _$RepairInfoModelFromJson(json);
  Map<String, dynamic> toJson() => _$RepairInfoModelToJson(this);
}

class RepairInfoController extends GetControllerEx<RepairInfoModel> {
  // RepairRepository repairRepository = RepairRepository();
  RepairInfoController() {
    attr = GetModel(RepairInfoModel()).obs;
  }

  // Future<void> initData(ApplyRepairModel applyRepairModel) async {
  //   if (applyRepairModel != null) {
  //     final List<dynamic> fetchedRepairs =
  //         await repairRepository.findData(applyRepairModel.id!);
  //     RepairListController repairListController = Get.find();
  //     final List<dynamic> info = await repairListController.repairRepository
  //         .findRecordData(applyRepairModel.id!);
  //     if (info.isNotEmpty) {
  //       List<ApplyRepairModel> infos = [];
  //       List<dynamic> tmp = info as List<dynamic>;
  //       try {
  //         infos =
  //             tmp.map((repair) => ApplyRepairModel.fromJson(repair)).toList();
  //         model.applyRepairModel = infos.first;
  //         updateAll();
  //       } catch (e) {
  //         print('Error parsing JSON: $e');
  //       }
  //       // model.applyRepairModel = applyRepairModel;
  //     }

  //     if (fetchedRepairs != null) {
  //       List<RepairProcessModel> infos = [];
  //       List<dynamic> tmp = fetchedRepairs as List<dynamic>;
  //       try {
  //         infos =
  //             tmp.map((repair) => RepairProcessModel.fromJson(repair)).toList();
  //         model.repairProcessList = infos;
  //         updateAll();
  //       } catch (e) {
  //         print('Error parsing JSON: $e');
  //       }
  //     }
  //   }
  // }
}
