/**
 * Member Service
 * Handles member-related API calls
 */

import { ApiService } from './ApiService';

export const MemberService = {
  /**
   * Get member profile
   */
  getProfile: async (memberId) => {
    try {
      const response = await ApiService.get(`/members/${memberId}`);
      return response;
    } catch (error) {
      throw error;
    }
  },

  /**
   * Get member balance
   */
  getBalance: async (memberId) => {
    try {
      const response = await ApiService.get(`/members/balance/${memberId}`);
      return response;
    } catch (error) {
      throw error;
    }
  },

  /**
   * Update member profile
   */
  updateProfile: async (memberId, data) => {
    try {
      const response = await ApiService.put(`/members/${memberId}`, data);
      return response;
    } catch (error) {
      throw error;
    }
  },

  /**
   * Get member contributions
   */
  getContributions: async (memberId, page = 1, perPage = 20) => {
    try {
      const response = await ApiService.get('/contributions', {
        member_id: memberId,
        page,
        per_page: perPage,
      });
      return response;
    } catch (error) {
      throw error;
    }
  },

  /**
   * Get member withdrawals
   */
  getWithdrawals: async (memberId, page = 1, perPage = 20) => {
    try {
      const response = await ApiService.get('/withdrawals', {
        member_id: memberId,
        page,
        per_page: perPage,
      });
      return response;
    } catch (error) {
      throw error;
    }
  },

  /**
   * Get member policies
   */
  getPolicies: async (memberId) => {
    try {
      const response = await ApiService.get('/policies', {
        member_id: memberId,
      });
      return response;
    } catch (error) {
      throw error;
    }
  },

  /**
   * Get member statement
   */
  getStatement: async (memberId, startDate, endDate) => {
    try {
      const response = await ApiService.get('/statements', {
        member_id: memberId,
        start_date: startDate,
        end_date: endDate,
      });
      return response;
    } catch (error) {
      throw error;
    }
  },
};
