import BasicService from './BasicService';

/**
 * @desc 全局服务
 */
class AccountService extends BasicService {
  constructor() {
    super();
  }

  pk = async () => {
    return await this.get('/gateway/idm/api/pk');
  };

  fakeAccountLogin = async (data: any) => {
    return await this.post('/gateway/idm/api/token/login', data);
  };

  fakeAccountChangePassword = async (data: any) => {
    return await this.post('/gateway/idm/api/account/change-password', data);
  };

  fakeLogout = async () => {
    return this.get('/gateway/idm/api/logout');
  };

  getAccountInfo = async () => {
    return this.get(`/gateway/idm/api/account/current/info`);
  };

  // ===============  人员相关  ==================================

  /**
   * 获取用户信息
   */
  getUserAddressClassTree = async (data: any) => {
    return this.post(
      `/gateway/idm/api/idmComponent/getUserAddressClassTree`,
      data,
    );
  };

  /**
   *
   * @param 查询用户当前公司所在的所有组织
   * @returns
   */
  searchUserInAddressClassTreeAndParentNo = async (data: any) => {
    return this.post(
      `/gateway/idm/api/idmComponent/searchUserInAddressClassTreeAndParentNo`,
      data,
    );
  };

  /**
   * 搜索人员信息
   */
  searchUserInAddressClassTree = async (data: any) => {
    return this.post(
      `/gateway/idm/api/idmComponent/searchUserInAddressClassTree`,
      data,
    );
  };

  /**
   * 后端可切换的企业列表
   */
  tenants = async () => {
    return this.get(`/gateway/idm/api/account/tenants`);
  };

  /**
   * 后端可切换的组织列表
   */
  organizations = async (tenantId: string) => {
    return this.get(
      `/gateway/idm/api/account/console/organizations/${tenantId}?roleNos=`,
    );
  };

  /**
   * 切换租户或组织
   */
  tenantAndBaseOrgIdChange = async (data: any) => {
    const { tenantId, baseOrgId } = data;
    return this.get(
      `/gateway/idm/api/token/tenant-and-baseOrgId-change/${tenantId}?baseOrgId=${baseOrgId}&needCheck=F`,
    );
  };

  /**
   * 更新人员信息
   */
  updateUserInfo = async (dto: any) => {
    return this.post(`/gateway/idm/api/idm-users/updateUserInfo`, dto);
  };

  /**
   * 获取人员信息
   */
  getCommonUserInfoByUserNo = async (userNo: string) => {
    return this.get(
      `/gateway/idm/api/idm-users/getCommonUserInfoByUserNo/${userNo}`,
    );
  };
}

const accountService = new AccountService();

export default accountService;
