import apiClient from './client' import type { Token, User, UserCreate, UserLogin, UserUpdate } from '@/types' export const authApi = { async register(data: UserCreate): Promise { const response = await apiClient.post('/auth/register', data) return response.data }, async login(data: UserLogin): Promise { const response = await apiClient.post('/auth/login/json', data) return response.data }, async refresh(): Promise { const refreshToken = localStorage.getItem('refresh_token') const response = await apiClient.post('/auth/refresh', null, { headers: { Authorization: `Bearer ${refreshToken}`, }, }) return response.data }, async me(): Promise { const response = await apiClient.get('/auth/me') return response.data }, async logout(): Promise { await apiClient.post('/auth/logout') }, async changePassword(currentPassword: string, newPassword: string): Promise { await apiClient.post('/auth/password/change', { current_password: currentPassword, new_password: newPassword, }) }, async forgotPassword(email: string): Promise { await apiClient.post('/auth/password/forgot', { email }) }, async verifyResetToken(token: string): Promise<{ valid: boolean; email: string | null }> { const response = await apiClient.post<{ valid: boolean; email: string | null }>('/auth/password/verify-reset-token', { token }) return response.data }, async resetPassword(token: string, newPassword: string): Promise { await apiClient.post('/auth/password/reset', { token, new_password: newPassword, }) }, async updateProfile(data: UserUpdate): Promise { const response = await apiClient.patch('/auth/me', data) return response.data }, async getVerificationStatus(): Promise<{ enabled: boolean }> { const response = await apiClient.get<{ enabled: boolean }>('/auth/email/verification-status') return response.data }, async sendVerificationEmail(): Promise { await apiClient.post('/auth/email/send-verification') }, async verifyEmail(token: string): Promise { await apiClient.post('/auth/email/verify', { token }) }, } export default authApi