import { apiClient } from './client';
import type { Position } from '../types/models';

export interface ClosePositionParams {
  symbol: string;
  quantity?: number;
  type?: 'market' | 'limit';
  price?: number;
}

export async function getPositions(symbol?: string): Promise<Position[]> {
  const response = await apiClient.get<Position[]>('/api/positions', {
    params: symbol ? { symbol } : undefined,
  });
  return response.data;
}

export async function closePosition(positionId: string): Promise<Position> {
  const response = await apiClient.post<Position>(`/api/positions/${positionId}/close`);
  return response.data;
}

export async function closeAllPositions(symbol?: string): Promise<Position[]> {
  const response = await apiClient.post<Position[]>('/api/positions/close-all', {
    params: symbol ? { symbol } : undefined,
  });
  return response.data;
}
