import type { AxiosResponse } from 'axios'

import request from '@/utils/request'
import type { Result, FrameUserInfo } from '@cacp/ui'
import config from '@/config'

const contextPath = '/mock'

export async function getFrameUser(): Promise<Result<FrameUserInfo>> {
  const res: AxiosResponse<Result<FrameUserInfo>> = await request.get(`${contextPath}/get-frame-user`)
  return res.data
}

export async function setMockUser(viewCode: string, fullPathName: string): Promise<Result<boolean>> {
  const res: AxiosResponse<Result<boolean>> = await request.get(`${contextPath}/set-mock-user`, {
    params: { viewCode: viewCode, appCode: config.AUTH_APP_CODE, fullPathName: fullPathName }
  })
  return res.data
}

export async function clearMockUser() {
  await request.get(`${contextPath}/clear-mock-user`)
}
