import 'package:ef/ef.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:vbvs_app/common/color/ServiceConstant.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/requestWithLog.dart';
import 'package:vbvs_app/model/api_response.dart';
import 'apply_repair_controller.dart';
part 'repair_list_controller.g.dart';

@JsonSerializable()
class RepairListModel {
  int limit = AppConstants.limit;
  int offset = 0;
  bool isLoading = false;
  bool hasMore = true;

  List repairList = [];

  RepairListModel();
  static RepairListModel fromJson(Map<String, dynamic> json) =>
      _$RepairListModelFromJson(json);
  Map<String, dynamic> toJson() => _$RepairListModelToJson(this);
}

class RepairListController extends GetControllerEx<RepairListModel> {
  RepairListController() {
    attr = GetModel(RepairListModel()).obs;
  }

  //初始化列表数据
  @override
  Future<void> onInit() async {
    super.onInit();
    await getRepairList();
  }

  getRepairList() async {
    String serviceAddress = ServiceConstant.service_address;
    String serviceName = ServiceConstant.server_service;
    String serviceApi = ServiceConstant.submit_repair;
    String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
    await requestWithLog(
      logTitle: "查询报修数据",
      method: MyHttpMethod.get,
      queryUrl: queryUrl,
      onSuccess: (res) {
        model.repairList = res.data;
        updateAll();
      },
    );
  }

  // Future<String> addScore(int id, int score) async {
  //   return await repairRepository.addScore(id, score);
  // }
}
