import { SaveUserType, UserTableAPIType } from '@/types'
import http from '@/utils/http'
import { AppDispatch } from '..'
/**
 * 获取用户管理表格列表
 */
export const A9API_getUserListAPI = (data: UserTableAPIType): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('sys/user/list', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }

      dispatch({ type: 'user/getList', payload: obj })
    }
  }
}

/**
 * 用户-是否显示
 */
export const A9API_userDisplayAPI = (id: number, display: number) => {
  return http.get(`sys/user/editStatus/${id}/${display}`)
}

/**
 * 删除用户
 */
export const A9API_userRemoveAPI = (id: number) => {
  return http.get(`sys/user/removes/${id}`)
}

/**
 * 重置密码
 */
export const A9API_userPassResetAPI = (id: number) => {
  return http.get(`sys/user/resetPass/${id}`)
}

/**
 * 新增/修改用户信息
 */
export const A9API_userSaveAPI = (data: SaveUserType) => {
  return http.post('sys/user/save', data)
}

/**
 * 通过id获取角色详情
 */
export const A9API_getUserInfoByIdAPI = (id: number) => {
  return http.get(`sys/user/detail/${id}`)
}
