"use server";

import { streamAIResponse } from "@/lib/ai/stream";
import {
  calculateBazi,
  formatBaziForPrompt,
  type BaziInput,
} from "@/lib/calc/bazi";
import { BAZI_SYSTEM_PROMPT } from "@/lib/prompts";

export async function getBaziAnswer(
  input: BaziInput,
  question: string,
  birthPlaceName: string,
) {
  const chart = calculateBazi(input);
  const chartText = formatBaziForPrompt(chart);

  return streamAIResponse(
    BAZI_SYSTEM_PROMPT,
    `【出生时空】
出生地：${birthPlaceName}

【排盘信息】
${chartText}

【问事】
${question}`,
  );
}
