import { apiClient } from './client'
import type { SpreadBet, SpreadBetCreate, SpreadBetDetail } from '@/types/spread-bet'

export const spreadBetsApi = {
  createBet: async (betData: SpreadBetCreate): Promise<SpreadBet> => {
    const response = await apiClient.post<SpreadBet>('/api/v1/spread-bets', betData)
    return response.data
  },

  takeBet: async (betId: number): Promise<SpreadBet> => {
    const response = await apiClient.post<SpreadBet>(`/api/v1/spread-bets/${betId}/take`)
    return response.data
  },

  getMyActiveBets: async (): Promise<SpreadBetDetail[]> => {
    const response = await apiClient.get<SpreadBetDetail[]>('/api/v1/spread-bets/my-active')
    return response.data
  },

  getMyBetHistory: async (): Promise<SpreadBetDetail[]> => {
    const response = await apiClient.get<SpreadBetDetail[]>('/api/v1/spread-bets/my-history')
    return response.data
  },

  cancelBet: async (betId: number): Promise<{ message: string }> => {
    const response = await apiClient.delete<{ message: string }>(`/api/v1/spread-bets/${betId}`)
    return response.data
  },
}
