/*
 * @Author: XianKaiQun
 * @Date: 2020-07-30 09:03:35
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-08-10 16:25:58
 * @Description: 
 */
import 'package:app_package/app_package.dart';
import 'package:qrcode_package/src/models/clean_record.dart';
import 'package:qrcode_package/src/models/clean_security_list.dart';
import 'package:qrcode_package/src/models/clean_template.dart';
import 'package:qrcode_package/src/models/qrcode_detail.dart';
import 'package:qrcode_package/src/service/clean_service.dart';

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

  static String prefix = '/app/admin';

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

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

  @override
  Future<ResModel<PagingModel<CleanSecurityListModel>>> getCleanList(
      data) async {
    var res = await HttpUtil.instance.get(
      '/app/admin/cleanRecord',
      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?>> postCleanRecord(data) async {
    var res = await HttpUtil.instance.post(
      '/app/admin/cleanRecord',
      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,
    );
  }
}
