/*
 * @Author: XianKaiQun
 * @Date: 2020-07-30 09:03:35
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-08-10 16:31:45
 * @Description: 
 */
import 'package:app_package/app_package.dart';
import 'package:qrcode_package/src/models/clean_security_list.dart';
import 'package:qrcode_package/src/models/qrcode_detail.dart';
import 'package:qrcode_package/src/models/security_record.dart';
import 'package:qrcode_package/src/models/security_template.dart';
import 'package:qrcode_package/src/service/security_service.dart';

class SecurityServiceImpl implements SecurityService {
  static SecurityServiceImpl? get instance => _getInstance();
  static SecurityServiceImpl? _instance;
  SecurityServiceImpl._internal();
  static SecurityServiceImpl? _getInstance() {
    if (_instance == null) {
      _instance = new SecurityServiceImpl._internal();
    }
    return _instance;
  }

  static String prefix = '/app/admin';

  @override
  Future<ResModel<SecurityTemplateModel>> getSecurityTemplate(data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/securityPatrolsTemplate',
      queryParameters: data,
    );
    print(res.data);
    return ResModel<SecurityTemplateModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => SecurityTemplateModel.fromJson(v),
    );
  }

  @override
  Future<ResModel<SecurityRecordModel>> getSecurityDetail(String? id) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/securityPatrolsRecord/detail',
      queryParameters: {'id': id},
    );
    return ResModel<SecurityRecordModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => SecurityRecordModel.fromJson(v),
    );
  }

  @override
  Future<ResModel<PagingModel<CleanSecurityListModel>>> getSecurityList(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/securityPatrolsRecord',
      queryParameters: data,
    );

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

  @override
  Future<ResModel<String?>> postSecurityRecord(data) async {
    var res = await HttpUtil.instance.post(
      '/app/admin/securityPatrolsRecord',
      data: data,
    );
    return ResModel<String?>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }

  @override
  Future<ResModel<QrcodeDetailModel>> getQrcodeDetail(String? id) async {
    var res = await HttpUtil.instance.get(
      'app/admin/qrcodeManagement',
      queryParameters: {'id': id},
    );
    return ResModel<QrcodeDetailModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => QrcodeDetailModel.fromJson(v),
    );
  }

  @override
  Future<ResModel<List<Map>?>> getEquipmentStatusEnum() async {
    var res = await HttpUtil.instance.get(
      'app/admin//equipment/status',
    );
    return ResModel<List<Map>?>(
      json: res.data['list'],
      to: (v) => v,
      from: (v) => v,
    );
  }

  @override
  Future<ResModel<List<Map>?>> getQrcodetypeEnum() async {
    var res = await HttpUtil.instance.get(
      'app/admin/qrcodeManagement/qrType',
    );
    return ResModel<List<Map>?>(
      json: res.data,
      to: (v) => v,
      from: (v) => v,
    );
  }
}
