import axios from 'axios';
import { getApiBaseUrl } from './apiConfig';

const API_BASE_URL = getApiBaseUrl().replace('/api', '');

export interface CryptoHoldingDto {
  id?: number;
  symbol: string;
  koreanName: string;
  englishName?: string;
  displayOrder?: number;
  createdAt?: string;
}

export const getAllHoldings = async (): Promise<CryptoHoldingDto[]> => {
  const response = await axios.get(`${API_BASE_URL}/api/holdings`);
  return response.data;
};

export const addHolding = async (dto: CryptoHoldingDto): Promise<CryptoHoldingDto> => {
  const response = await axios.post(`${API_BASE_URL}/api/holdings`, dto);
  return response.data;
};

export const removeHolding = async (symbol: string): Promise<void> => {
  await axios.delete(`${API_BASE_URL}/api/holdings/${symbol}`);
};

export const toggleHolding = async (dto: CryptoHoldingDto): Promise<boolean> => {
  const response = await axios.post(`${API_BASE_URL}/api/holdings/toggle`, dto);
  return response.data.isHolding;
};
