import apiClient from './api';

const teamService = {
  /**
   * 이벤트별 팀 목록 조회
   * @param {number|string} eventId
   * @returns {Promise<Array>} 팀 배열
   */
  async getTeams(eventId) {
    const response = await apiClient.get(`/api/club/events/${eventId}/teams`);
    return response.data.teams;
  },
  /**
   * 이벤트별 팀 저장
   * @param {number|string} eventId
   * @param {Array} teams - [{ teamNumber, handicap, members: [id, ...] }]
   */
  async saveTeams(eventId, teams) {
    const payload = teams.map((team, idx) => ({
      teamNumber: team.teamNumber ?? idx + 1,
      handicap: team.handicap || 0,
      members: team.members
    }));
    return apiClient.post(`/api/club/events/${eventId}/teams`, { teams: payload });
  },

  // 추후: 팀 불러오기, 수정, 삭제 등 추가 가능
};

export default teamService;
