import { fetchWithAuth } from "./client";

function buildQuery(params: Record<string, string | number | boolean | undefined>): string {
  const qs = Object.entries(params)
    .filter(([, v]) => v !== undefined)
    .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
    .join("&");
  return qs ? `?${qs}` : "";
}

export const suggestionsApi = {
  /** 获取建议列表 */
  getSuggestions: (
    token: string,
    brandId: string,
    params?: Record<string, string | number>
  ) =>
    fetchWithAuth(
      `/api/v1/suggestions/${brandId}/suggestions${buildQuery(params || {})}`,
      {},
      token
    ),

  /** 重新生成建议 */
  regenerateSuggestions: (token: string, brandId: string) =>
    fetchWithAuth(
      `/api/v1/suggestions/${brandId}/suggestions/regenerate`,
      { method: "POST" },
      token
    ),

  /** 更新建议状态 */
  updateSuggestionStatus: (
    token: string,
    brandId: string,
    suggestionId: string,
    status: string
  ) =>
    fetchWithAuth(
      `/api/v1/suggestions/${brandId}/suggestions/${suggestionId}/status`,
      { method: "PUT", body: JSON.stringify({ status }) },
      token
    ),
};
