import client from './client'

export interface LoginRequest {
  account: string
  password: string
  captchaKey: string
  captchaCode: string
}

export interface RegisterRequest {
  username: string
  password: string
  email: string
  nickname: string
  phone?: string
  emailCode: string
}

export const authApi = {
  getCaptcha: () => client.get<{ data: { key: string; image: string } }>('/auth/captcha'),

  sendEmailCode: (email: string, purpose: string) =>
    client.post('/auth/send-email-code', null, { params: { email, purpose } }),

  register: (data: RegisterRequest) => client.post('/auth/register', data),

  login: (data: LoginRequest) =>
    client.post<{ data: { token: string } }>('/auth/login', data),

  forgotPassword: (email: string) =>
    client.post('/auth/forgot-password', null, { params: { email } }),

  resetPassword: (email: string, code: string, newPassword: string) =>
    client.post('/auth/reset-password', null, { params: { email, code, newPassword } }),
}
