// frontend/lib/hooks/useSettings.ts — 설정 SWR 훅(시스템·LLM·프로필·토큰)
"use client";
import useSWR from "swr";
import type { LlmConfig, Me, SystemConfig, TokenInfo } from "@/lib/types";
import { settingsApi } from "@/lib/settings/api";

export function useSystemConfig() {
  const { data, error, isLoading, mutate } = useSWR<SystemConfig>(
    "/api/settings/system",
    () => settingsApi.system(),
    { revalidateOnFocus: false },
  );
  return { data, error, isLoading, refresh: mutate };
}

export function useLlmConfig() {
  const { data, error, isLoading, mutate } = useSWR<LlmConfig>(
    "/api/settings/llm",
    () => settingsApi.getLlm(),
    { revalidateOnFocus: false },
  );
  return { data, error, isLoading, refresh: mutate };
}

export function useMe() {
  const { data, error, isLoading, mutate } = useSWR<Me>("/api/me", () => settingsApi.me(), {
    revalidateOnFocus: false,
    shouldRetryOnError: false,
  });
  return { data, error, isLoading, refresh: mutate };
}

export function useTokens() {
  const { data, error, isLoading, mutate } = useSWR<TokenInfo[]>(
    "/api/me/tokens",
    () => settingsApi.listTokens(),
    { revalidateOnFocus: false, shouldRetryOnError: false },
  );
  return { data, error, isLoading, refresh: mutate };
}
