import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SysAgentVO, SysAgentForm, SysAgentQuery, SysUserAgentForm } from '@/api/system/sysAgent/types';

/**
 * 查询代理信息拓展列表
 * @param query
 * @returns {*}
 */

export const listSysAgent = (query?: SysAgentQuery): AxiosPromise<SysAgentVO[]> => {
  return request({
    url: '/system/agent/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询代理信息拓展详细
 * @param userId
 */
export const getSysAgent = (userId: string | number): AxiosPromise<SysAgentVO> => {
  return request({
    url: '/system/agent/' + userId,
    method: 'get'
  });
};

/**
 * 新增代理信息拓展
 * @param data
 */
export const addSysAgent = (data: SysUserAgentForm) => {
  return request({
    url: '/system/agent',
    method: 'post',
    data: data
  });
};

/**
 * 修改代理信息拓展
 * @param data
 */
export const updateSysAgent = (data: SysUserAgentForm) => {
  return request({
    url: '/system/agent',
    method: 'put',
    data: data
  });
};

/**
 * 删除代理信息拓展
 * @param userId
 */
export const delSysAgent = (userId: string | number | Array<string | number>) => {
  return request({
    url: '/system/agent/' + userId,
    method: 'delete'
  });
};

/**
 * 批量更新用户状态
 * @param userIds
 * @param status
 */
export const updateBatchUserStatus = (userIds: (string | number)[], status: string) => {
  return request({
    url: '/system/agent/batchChangeStatus',
    method: 'put',
    params: {
      userIds: userIds,
      status: status
    }
  });
};

/**
 * 导出代理用户列表
 * @param query
 */
export const exportSysAgent = (query?: SysAgentQuery) => {
  return request({
    url: '/system/agent/export',
    method: 'post',
    data: query,
    responseType: 'blob'
  });
};

/**
 * 代理用户密码重置
 * @param userId 用户ID
 * @param password 密码
 */
export const resetAgentPwd = (userId: string | number, password: string) => {
  const data = {
    userId,
    password
  };
  return request({
    url: '/system/agent/resetPwd',
    method: 'put',
    headers: {
      isEncrypt: true,
      repeatSubmit: false
    },
    data: data
  });
};

