import request from './request'

export interface LoginRes {
  access_token: string
  refresh_token: string
  token_type: string
  expires_in: number
}

export interface UserInfo {
  id: number
  username: string
  email?: string
  real_name?: string
  phone?: string
  is_active: boolean
  is_superuser: boolean
  dept?: { id: number; name: string }
  roles: { id: number; name: string; code: string }[]
}

export function login(username: string, password: string): Promise<LoginRes> {
  return request.post('/auth/login', { username, password }).then((res: any) => res.data)
}

export function getMe(): Promise<UserInfo> {
  return request.get('/users/me').then((res: any) => res.data)
}
