import request from '@/service/request'

export const login = (data: USER.Params.Login) => {
  return request<USER.Tenant.Detail>({
    url: '/auth/login',
    method: 'POST',
    data
  })
}

export const page = (params: USER.Params.Query) => {
  return request<USER.User.Detail[]>({
    url: '/user/page',
    method: 'GET',
    params
  })
}

export const list = (params: {limit: number, userLabel: string}) => {
  return request<USER.User.Detail[]>({
    url: '/user/list',
    method: 'GET',
    params
  })
}

export const addUser = (data: USER.User.Detail) => {
  return request<string>({
    url: '/user',
    method: 'POST',
    data
  })
}

export const getUserById = (id: string) => {
  return request<USER.User.Detail>({
    url: `/user/${id}`,
    method: 'GET'
  })
}

/**
 *
 * @param "id": "admin" 用户id 必需
 * @param "sourcePassword": "admin" 原始密码  做一次base64 encode
 * @param "newPassword": "admin" 新密码  必需，在输入的密码上   做一次base64 encode
 */
export const updatePassword = (data: {id: string, sourcePassword: string, newPassword: string}) => {
  return request<string>({
    url: '/user/password',
    method: 'PUT',
    data
  })
}

export const resourcePage = (params: USER.Params.Query & {resourceLabel: string}) => {
  return request<USER.Resource.Detail[]>({
    url: '/resource/page',
    method: 'GET',
    params
  })
}
