/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2023-02-13 14:20:02
 * @LastEditTime : 2023-05-25 15:54:50
 * @Description  : Do not edit
 */
import 'package:app_package/app_package.dart';
import 'package:qrcode_package/src/models/name_code.dart';
import 'package:qrcode_package/src/models/name_id.dart';
import 'package:qrcode_package/src/models/norm.dart';
import 'package:qrcode_package/src/models/norm_detail.dart';
import 'package:qrcode_package/src/models/place.dart';
import 'package:qrcode_package/src/models/position_info.dart';
import 'package:qrcode_package/src/service/register_service.dart';

class RegisterServiceImpl implements RegisterService {
  @override
  Future<ResModel<List<NameCodeModel>?>> getStatusList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/equipment/status',
      queryParameters: data,
    );
    res.data['data'] = res.data['data']['list'];
    return ResModel<List<NameCodeModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<NameCodeModel>((f) => NameCodeModel.fromJson(f))
          .toList(),
    );
  }

  @override
  Future<ResModel<List<PlaceModel>?>> getRoomList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/equipment/rooms',
      queryParameters: data,
    );

    return ResModel<List<PlaceModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<PlaceModel>((f) => PlaceModel.fromJson(f)).toList(),
    );
  }

  @override
  Future<ResModel<List<PlaceModel>?>> getBuildList(data) async {
    var res = await HttpUtil.instance.get(
      'app/admin/assets/getBuildInfo',
      queryParameters: data,
    );
    return ResModel<List<PlaceModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<PlaceModel>((f) => PlaceModel.fromJson(f)).toList(),
    );
  }

  @override
  Future<ResModel<List<PlaceModel>?>> getHouseList(data) async {
    var res = await HttpUtil.instance.get(
      'app/admin/assets/getHouseInfo',
      queryParameters: data,
    );
    return ResModel<List<PlaceModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<PlaceModel>((f) => PlaceModel.fromJson(f)).toList(),
    );
  }

  @override
  Future<ResModel<List<PlaceModel>?>> getUnitList(data) async {
    var res = await HttpUtil.instance.get(
      'app/admin/assets/getUnitInfo',
      queryParameters: data,
    );
    return ResModel<List<PlaceModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<PlaceModel>((f) => PlaceModel.fromJson(f)).toList(),
    );
  }

  /// 设备品类列表
  /// http://yapi.wisdomcity.com.cn/project/16/interface/api/4856
  Future<ResModel<List<NameIdModel>>> getCatagoryList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/equipment/categorys',
      queryParameters: data,
    );

    return ResModel<List<NameIdModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<NameIdModel>((f) => NameIdModel.fromJson(f)).toList(),
    );
  }

  /// 设备品牌及类型列表
  /// http://yapi.wisdomcity.com.cn/project/16/interface/api/4831
  Future getEquipmentTypes(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/equipment/types',
      queryParameters: data,
    );

    return res.data;
  }

  /// 设备负责人
  Future<ResModel<List<NameIdModel>>> getEquipmentPersonList(data) async {
    var res = await HttpUtil.instance.get(
      'app/admin/equipment/managers',
      queryParameters: data,
    );

    return ResModel<List<NameIdModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<NameIdModel>((f) => NameIdModel.fromJson(f)).toList(),
    );
  }

  /// 规范
  /// http://yapi.wisdomcity.com.cn/project/16/interface/api/4836
  Future<ResModel<List<NormModel>>> getNormList(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/equipment/norms',
      queryParameters: data,
    );

    return ResModel<List<NormModel>>(
      json: res.data,
      to: (v) => (v).map((f) => f.toJson()).toList(),
      from: (v) =>
          (v ?? []).map<NormModel>((f) => NormModel.fromJson(f)).toList(),
    );
  }

  /// 规范详情
  /// http://yapi.wisdomcity.com.cn/project/16/interface/api/5256
  Future<ResModel<NormDetailModel>> getNormDetail(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/equipment/norm/${data['id']}',
      queryParameters: data,
    );

    return ResModel<NormDetailModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => NormDetailModel.fromJson(v),
    );
  }

  /// 扫码设备登记信息
  /// http://yapi.wisdomcity.com.cn/project/16/interface/api/3419
  Future<ResModel<String>> postEquipment(data) async {
    var res = await HttpUtil.instance.post(
      '/app/admin/equipment',
      data: data,
    );

    return ResModel<String>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }

  /// 位置选择树
  /// http://yapi.wisdomcity.com.cn/project/16/interface/api/5266

  Future<ResModel<PositionInfoModel>> getPositionInfo(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/qrcodeManagement/tree',
      queryParameters: data,
    );

    return ResModel<PositionInfoModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => PositionInfoModel.fromJson(v),
    );
  }

  Future<ResModel<int>> postQrcode(data) async {
    var res = await HttpUtil.instance.post(
      '/app/admin/qrcodeManagement',
      data: data,
    );

    return ResModel<int>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }
}
