import request from '@/config/axios'
import type { UserType } from './types'

interface RoleParams {
  userId: string
}

export const loginApi = (data: any): Promise<IResponse<any>> => {
  return request.postJson({ url: '/system/spi/system/auth/pclogin', data })
}

export const loginSso = (ssoToken: string): Promise<IResponse<any>> => {
  return request.postJson({ url: '/system/spi/system/auth/ssoLogin', data:{ssoToken} })
}

export const loginOutApi = (): Promise<IResponse<any>> => {
  return request.postJson({ url: '/system/spi/system/auth/pclogout' })
}

export const getUserListApi = ({ params }: AxiosConfig) => {
  return request.get<{
    code: string
    data: {
      list: UserType[]
      total: number
    }
  }>({ url: '/user/list', params })
}

export const getMenuTreeByRole = (
  params: RoleParams
): Promise<IResponse<AppCustomRouteRecordRaw[]>> => {
  return request.get({ url: '/system/spi/system/auth/UserRoleMenu', params })
}

export const getMenuKeysByRole = (params: RoleParams): Promise<IResponse<string[]>> => {
  return request.get({ url: '/system/spi/system/auth/UserRoleMenu', params })
}
