import request from './request'

export interface LoginParams {
  username: string
  password: string
}

export interface UserInfo {
  id: number
  username: string
  email: string
  phone: string
  nickname: string
  status: number
  roleId: number
}

export interface LoginResponse {
  accessToken: string
  refreshToken: string
  tokenType: string
  expiresIn: number
  userInfo: UserInfo
}

export interface ApiResponse<T> {
  code: number
  message: string
  data: T
}

export function login(params: LoginParams): Promise<ApiResponse<LoginResponse>> {
  return request.post('/api/auth/login', { ...params, target: 'admin' })
}

export function getUserInfo(id: number): Promise<ApiResponse<UserInfo>> {
  return request.get(`/api/auth/users/${id}`)
}

export function verifyPassword(params: LoginParams): Promise<ApiResponse<LoginResponse>> {
  return request.post('/api/auth/login', params)
}