import { post } from './request'

export type MpRoleType = 'mp-sales' | 'mp-dispatch' | 'mp-construction'

export interface LoginParams {
  username: string
  password: string
  roleType?: MpRoleType
}

export interface LoginMenu {
  menuId: number
  menuName: string
  parentId?: number
  orderNum?: number
  path?: string
  component?: string
  icon?: string
  menuType?: string
  children?: LoginMenu[]
}

export interface LoginResult {
  token: string
  userId: number
  userName: string
  nickName: string
  roleType: string
  roleId?: number
  roleName?: string
  roleKey?: string
  homePath?: string
  avatar: string
  phonenumber?: string
  phone?: string
  email?: string
  dept?: { deptName?: string; deptId?: number; name?: string }
  position?: string
  employeeNo?: string
  hireDate?: string
  team?: string
  department?: string
  needChangePassword?: boolean
  menus?: LoginMenu[]
  permissions?: string[]
  endpoints?: string[]
}

export function login(params: LoginParams) {
  return post<LoginResult>('/auth/login', params)
}

export function logout() {
  return post('/auth/logout')
}

export function debugPassword() {
  return post('/auth/debug-password')
}

export function resetPassword() {
  return post('/auth/reset-password')
}

export function initData() {
  return post('/auth/init-data')
}
