import { apiClient } from './client';

// ═══ 대시보드 CRUD (Phase 4 — /api/dashboards) ═══

export async function getDashboardList(params?: Record<string, any>) {
  const res = await apiClient.get('/dashboards', { params });
  return res.data.data;
}

export async function getDashboardInfo(dashboardId: string) {
  const res = await apiClient.get(`/dashboards/${dashboardId}`);
  return res.data.success ? res.data.data : null;
}

export async function insertDashboard(data: Record<string, any>) {
  const res = await apiClient.post('/dashboards', data);
  return res.data.data;
}

export async function updateDashboard(dashboardId: string, data: Record<string, any>) {
  await apiClient.put(`/dashboards/${dashboardId}`, data);
}

export async function deleteDashboard(dashboardId: string) {
  await apiClient.delete(`/dashboards/${dashboardId}`);
}

// ═══ 카드 CRUD ═══

export async function getDashboardCards(dashboardId: string) {
  const res = await apiClient.get(`/dashboards/${dashboardId}/cards`);
  return res.data.data ?? [];
}

export async function insertDashboardCard(dashboardId: string, data: Record<string, any>) {
  const res = await apiClient.post(`/dashboards/${dashboardId}/cards`, data);
  return res.data.data;
}

export async function updateDashboardCard(dashboardId: string, cardId: string, data: Record<string, any>) {
  await apiClient.put(`/dashboards/${dashboardId}/cards/${cardId}`, data);
}

export async function deleteDashboardCard(dashboardId: string, cardId: string) {
  await apiClient.delete(`/dashboards/${dashboardId}/cards/${cardId}`);
}

export async function updateCardPositionsBatch(dashboardId: string, cards: Record<string, any>[]) {
  await apiClient.put(`/dashboards/${dashboardId}/cards/batch`, { cards });
}

