/*
 * @Author: XianKaiQun
 * @Date: 2020-04-22 09:28:36
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-04-11 15:07:02
 * @Descripttion: 
 */
import 'package:app_package/app_package.dart';
import 'package:app_package/src/models/community_picker.dart';

class EmployeeApi {
  static String _prefix = '/app/admin/employee';

  ///员工信息
  static Future<ResModel<EmployeesInfoModel>> getEmployeeInfo(id) async {
    var res = await HttpUtil.instance.get(
      '/auth/employees/$id',
    );

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

  ///获取管理的小区列表
  static Future<ResModel<List<CommunityModel>?>>
      getDomainCommunitysList() async {
    var res = await HttpUtil.instance.get('$_prefix/domainCommunitys');

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

  ///获取管理的小区列表-下拉选
  static Future<ResModel<List<CommunityPickerModel>>>
      getDomainCommunityListToPicker() async {
    var res = await HttpUtil.instance.get('$_prefix/domainCommunitys');

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