/*
 * @Author: WuXiangNan
 * @Date: 2021-02-22 09:55:42
 * @LastEditTime : 2022-01-19 16:39:20
 * @LastEditors  : WuWei
 * @Description: 考勤接口实现连接
 */

import 'package:app_package/app_package.dart';
import '../../models/response_model/clock_status/clock_status_data_model.dart';
import '../../models/response_model/attendance_rule/rule_data_model.dart';
import '../../models/response_model/attendance_rule/schedule_calendar_model.dart';
import '../../models/response_model/calendar/calendar_model.dart';
import '../attendance_service.dart';

class AttendanceServiceImpl implements AttendanceService {
  static String prefix = '/app/admin/attendance';

  //考勤打卡
  @override
  Future<bool?> postAttendanceClock(data) async {
    var res = await HttpUtil.instance.post(
      '$prefix/clock',
      // 'http://yapi.wisdomcity.com.cn/mock/40/app/admin/admin/attendance/clock',
      data: data,
    );

    if (res.data['data'] != null && res.data['data'] is bool) {
      return res.data['data'];
    } else {
      return null;
    }
  }

  //考勤打卡状态
  @override
  Future<ResModel<ClockStatusDataModel>> postClockStatus(data) async {
    var res = await HttpUtil.instance.post(
      '$prefix/clock/status',
      // 'http://yapi.wisdomcity.com.cn/mock/40/app/admin/admin/attendance/clock/status',
      data: data,
    );

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

  //考勤规则展示
  @override
  Future<ResModel<RuleModel>> getRuleShow(data) async {
    var res = await HttpUtil.instance.get(
      '$prefix/ruleShow',
      // 'http://yapi.wisdomcity.com.cn/mock/40/app/admin/admin/attendance/ruleShow',
      queryParameters: data,
    );

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

  //考勤规则展示 排班制日历
  @override
  Future<ResModel<List<ScheduleCalendarModel>?>> getScheduleCalendar(
      data) async {
    var res = await HttpUtil.instance.get(
      '$prefix/ruleShow/scheduleCalendar',
      // 'http://yapi.wisdomcity.com.cn/mock/40/app/admin/admin/attendance/ruleShow/scheduleCalendar',
      queryParameters: data,
    );

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

  //考勤日历
  @override
  Future<ResModel<List<CalendarModel>?>> getCalendar(data) async {
    var res = await HttpUtil.instance.get(
      '$prefix/calendar',
      // 'http://yapi.wisdomcity.com.cn/mock/40/app/admin/admin/attendance/calendar',
      queryParameters: data,
    );

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