/*
 * @Author: XianKaiQun
 * @Date: 2020-07-15 16:08:47
 * @LastEditors  : WuWei
 * @LastEditTime : 2021-05-27 10:24:04
 * @Description: 
 */

import 'package:app_package/app_package.dart';
import '../../src/models/dashboard_department.dart';
import '../../src/models/dashboard_person.dart';
import '../../src/models/dashboard_staff.dart';
import '../../src/service/dashboard_service.dart';

class DashboardServiceImpl implements DashboardService {
  static DashboardServiceImpl? get instance => _getInstance();
  static DashboardServiceImpl? _instance;
  DashboardServiceImpl._internal() {
    // 初始化
  }
  static DashboardServiceImpl? _getInstance() {
    if (_instance == null) {
      _instance = new DashboardServiceImpl._internal();
    }
    return _instance;
  }

  static String prefix = '/app/admin/excutive';
  @override
  Future<ResModel<DashboardPersonModel>> getPerson() async {
    var res = await HttpUtil.instance.get(
      '$prefix/v1/dashboard/person',
    );

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

  @override
  Future<ResModel<List<DashboardStaffModel>?>> getStaff() async {
    var res = await HttpUtil.instance.get(
      '$prefix/v1/dashboard/department/staff',
    );
    return ResModel<List<DashboardStaffModel>?>(
      json: res.data,
      to: (v) => (v ?? []).map((f) => f.toJson()).toList(),
      from: (v) => (v ?? [])
          .map<DashboardStaffModel>((f) => DashboardStaffModel.fromJson(f))
          .toList(),
    );
  }

  @override
  Future<ResModel<DashboardDepartmentModel>> getDepartment() async {
    var res = await HttpUtil.instance.get(
      '$prefix/v1/dashboard/department',
    );
    return ResModel<DashboardDepartmentModel>(
      json: res.data,
      to: (v) => v.toJson(),
      from: (v) => DashboardDepartmentModel.fromJson(v),
    );
  }
}
