import api from '../utils/request'

export interface CaptchaResponse {
  captcha_id: string
  image: string
  expire_seconds: number
}

export const getCaptcha = () => {
  return api.get<CaptchaResponse>('/utils/captcha')
}

export const sendSms = (data: { mobile: string, captcha_id: string, captcha_code: string }) => {
  return api.post('/open/sms/send', data)
}

export const resetPassword = (data: { mobile: string, sms_code: string, new_password: string }) => {
  return api.post('/open/pwd/reset', data)
}

export const getSystemStatus = () => {
  return api.get<{ initialized: boolean }>('/utils/init-status')
}

export const setupAdmin = (data: { mobile: string, sms_code: string, password: string }) => {
  return api.post('/utils/setup-admin', data)
}

export interface AppPublicInfo {
  app_id: string
  app_name: string
  protocol_type: 'OIDC' | 'SIMPLE_API' | 'NONE'
  redirect_uris: string
}

export const getAppPublicInfo = (appId: string) => {
  return api.get<AppPublicInfo>(`/open/apps/${appId}`)
}

export const ssoLogin = (data: { app_id: string, username: string, password: string }, config?: any) => {
  return api.post<{ redirect_url: string }>('/simple/sso-login', data, config)
}

export const registerDeveloper = (data: { mobile: string, password: string, sms_code: string, name: string }) => {
  return api.post('/open/register', data)
}

export interface DownloadLinksPublic {
  mobile: string | null
  pc: string | null
}

export const getDownloadLinks = () => {
  return api.get<DownloadLinksPublic>('/open/download-links')
}