import apiClient from './apiClient'; class AccountService { /** * Get all social accounts for the current user * @returns {Promise} Promise that resolves to the accounts data */ async getAll() { try { const response = await apiClient.get('/accounts'); if (import.meta.env.VITE_NODE_ENV === 'development') { console.log('📱 [Account] Retrieved accounts:', response.data); } return response; } catch (error) { if (import.meta.env.VITE_NODE_ENV === 'development') { console.error('📱 [Account] Get accounts error:', error.response?.data || error.message); } throw error; } } /** * Add a new social account * @param {Object} accountData - Account data * @param {string} accountData.account_name - Account name * @param {string} accountData.social_network - Social network name * @returns {Promise} Promise that resolves to the add account response */ async create(accountData) { try { const response = await apiClient.post('/accounts', { account_name: accountData.account_name, social_network: accountData.social_network }); if (import.meta.env.VITE_NODE_ENV === 'development') { console.log('📱 [Account] Account created:', response.data); } return response; } catch (error) { if (import.meta.env.VITE_NODE_ENV === 'development') { console.error('📱 [Account] Create account error:', error.response?.data || error.message); } throw error; } } /** * Delete a social account * @param {string} accountId - Account ID * @returns {Promise} Promise that resolves to the delete account response */ async delete(accountId) { try { const response = await apiClient.delete(`/accounts/${accountId}`); if (import.meta.env.VITE_NODE_ENV === 'development') { console.log('📱 [Account] Account deleted:', response.data); } return response; } catch (error) { if (import.meta.env.VITE_NODE_ENV === 'development') { console.error('📱 [Account] Delete account error:', error.response?.data || error.message); } throw error; } } /** * Handle OAuth callback * @param {Object} callbackData - OAuth callback data * @param {string} callbackData.code - Authorization code * @param {string} callbackData.state - State parameter * @param {string} callbackData.social_network - Social network name * @returns {Promise} Promise that resolves to the callback response */ async handleCallback(callbackData) { try { const response = await apiClient.post('/accounts/callback', { code: callbackData.code, state: callbackData.state, social_network: callbackData.social_network }); if (import.meta.env.VITE_NODE_ENV === 'development') { console.log('📱 [Account] OAuth callback handled:', response.data); } return response; } catch (error) { if (import.meta.env.VITE_NODE_ENV === 'development') { console.error('📱 [Account] OAuth callback error:', error.response?.data || error.message); } throw error; } } } export default new AccountService();