import 'dart:io';

import 'package:base_app/common/common.dart';
import 'package:base_app/data/api/apis.dart';
import 'package:base_app/data/net/dio_util.dart';
import 'package:base_app/data/protocol/base_resp.dart';
import 'package:base_app/data/protocol/model.dart';
import 'package:base_app/models/inspectionModel.dart';
import 'package:dio/dio.dart';

class InspectionRepository {
  // 获取巡检记录
  Future<List<InspectionModel>> getInspectionList(InspectionListReq req) async {
    BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
        .request<Map<String, dynamic>>(Method.get,
            AppApi.getPath(path: AppApi.inspection_list, resType: ''),
            data: req.toFormData());
    if (baseResp.code != Constant.status_success) {
      return new Future.error(baseResp.message);
    }
    List<InspectionModel> list;
    if (baseResp.data != null) {
      InspectionData inspectionData = InspectionData.fromJson(baseResp.data);
      list = inspectionData.datas?.map((value) {
        InspectionModel model = InspectionModel.fromJson(value);
        return model;
      })?.toList();
    }
    return list;
  }

  // 获取巡检详情
  Future<InspectionModel> getInspectionInfo(String id) async {
    FormData params = FormData.from({'id': id});
    BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
        .request<Map<String, dynamic>>(Method.get,
            AppApi.getPath(path: AppApi.inspection_info, resType: ''),
            data: params);
    if (baseResp.code != Constant.status_success) {
      return new Future.error(baseResp.message);
    }
    InspectionModel model;
    if (baseResp.data != null) {
      model = InspectionModel.fromJson(baseResp.data);
    }
    return model;
  }
}
