import { api } from '@/lib/api' import type { ApiResponse, UserProfile, UpdateUserRequest, UpdateUserSettingsRequest, DeleteAccountRequest, CheckinStatusResponse, CheckinResponse, } from './types' // ============================================================================ // User Profile APIs // ============================================================================ /** * Get current user profile */ export async function getUserProfile(): Promise> { const res = await api.get('/api/user/self') return res.data } /** * Update user profile */ export async function updateUserProfile( data: UpdateUserRequest ): Promise { const res = await api.put('/api/user/self', data) return res.data } /** * Update user settings */ export async function updateUserSettings( data: UpdateUserSettingsRequest ): Promise { const res = await api.put('/api/user/setting', data) return res.data } /** * Delete user account */ export async function deleteUserAccount( data?: DeleteAccountRequest ): Promise { const res = await api.delete('/api/user/self', { data }) return res.data } /** * Generate/regenerate system access token */ export async function generateAccessToken(): Promise> { const res = await api.get('/api/user/token') return res.data } // ============================================================================ // Account Binding APIs // ============================================================================ /** * Send email verification code */ export async function sendEmailVerification( email: string, turnstileToken?: string ): Promise { const params = new URLSearchParams({ email }) if (turnstileToken) { params.append('turnstile', turnstileToken) } const res = await api.get(`/api/verification?${params}`) return res.data } /** * Bind email account */ export async function bindEmail( email: string, code: string ): Promise { const res = await api.post('/api/oauth/email/bind', { email, code, }) return res.data } /** * Bind WeChat account */ export async function bindWeChat(code: string): Promise { const res = await api.get(`/api/oauth/wechat/bind?code=${code}`) return res.data } // ============================================================================ // Custom OAuth Binding APIs // ============================================================================ export interface CustomOAuthBinding { provider_id: string provider_name: string external_id?: string } /** * Get current user's custom OAuth bindings */ export async function getSelfOAuthBindings(): Promise< ApiResponse > { const res = await api.get('/api/user/oauth/bindings') return res.data } /** * Unbind a custom OAuth provider for current user */ export async function unbindCustomOAuth( providerId: string ): Promise { const res = await api.delete(`/api/user/oauth/bindings/${providerId}`) return res.data } // ============================================================================ // Checkin APIs // ============================================================================ /** * Get checkin status for a specific month */ export async function getCheckinStatus( month: string ): Promise> { const res = await api.get(`/api/user/checkin?month=${month}`) return res.data } /** * Perform daily checkin */ export async function performCheckin( turnstileToken?: string ): Promise> { const url = turnstileToken ? `/api/user/checkin?turnstile=${encodeURIComponent(turnstileToken)}` : '/api/user/checkin' const res = await api.post(url) return res.data }