/*
 * @Author: XianKaiQun
 * @Date: 2020-04-28 10:26:52
 * @LastEditors  : WuWei
 * @LastEditTime : 2022-03-03 17:19:40
 * @Descripttion: 
 */
import 'package:app_package/app_package.dart';
import 'package:task_package/src/models/operators.dart';
import 'package:task_package/src/models/operators_v3.dart';
import '../../src/models/operator.dart';
import '../../src/models/organ_tree.dart';

class AuthApi {
  ///部门树获取（前端定制）
  ///http://yapi.wisdomcity.com.cn/project/11/interface/api/1545
  static Future<ResModel<OrganTreeModel>> getOrganTree() async {
    var res = await HttpUtil.instance.get('/auth/organs/organWebTree');

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

  ///获取当前登陆人可选择OA员工执行人列表
  ///http://yapi.wisdomcity.com.cn/project/40/interface/api/19772
  static Future<ResModel<List<OperatorModel>?>> getOperatorList() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/employee/oa/list/app',
    );

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

  ///获取当前登陆人可选择OA员工执行人列表v2
  ///http://yapi.wisdomcity.com.cn/project/40/interface/api/19782
  static Future<ResModel<List<OperatorsModel>>> getOperatorListV2() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/employee/oa/list/v2',
    );

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

  ///获取当前登陆人可选择OA员工执行人列表v2
  ///http://yapi.wisdomcity.com.cn/project/40/interface/api/19782
  static Future<ResModel<List<OperatorsV3>>> getOperatorListV3() async {
    var res = await HttpUtil.instance.get(
      '/app/admin/employee/oa/list/v3',
    );

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