import type { BrandIntelligence, StoryIntelligence, VideoIntelligence } from "./types";

export function buildVideoIntelligence(
  brand: BrandIntelligence,
  story: StoryIntelligence,
  creativeBrief: string,
): VideoIntelligence {
  const hook =
    story.conflict.length > 80
      ? `${story.conflict.slice(0, 77)}…`
      : story.conflict;

  return {
    openingHook: hook || `What ${brand.industry} teams learn from ${story.letterToGodBeat.title}`,
    storyTimeline: [
      `Open: ${story.letterToGodBeat.situation}`,
      `Rise: ${story.conflict}`,
      `Turn: ${story.turningPoint}`,
      `Close: ${story.lesson}`,
    ].join(" → "),
    scenes: [
      `Scene 1 — Establish: ${brand.industry} context, ${story.emotions[0] ?? "hope"} mood`,
      `Scene 2 — Tension: visual metaphor for ${story.letterToGodBeat.title}`,
      `Scene 3 — Resolution: ${brand.companyName} value — ${story.keyTheme}`,
      `Scene 4 — CTA: ${story.engagementQuestion}`,
    ],
    musicMood:
      story.beatIndex === 1
        ? "Subdued, reflective — match industry tone"
        : "Uplifting, professional — match brand voice and industry",
    voiceTone: brand.brandVoice,
    endingEmotion: story.emotions[story.emotions.length - 1] ?? "confidence",
    cta: story.engagementQuestion,
  };
}

export function formatVideoIntelligenceMarkdown(video: VideoIntelligence): string {
  return [
    "## Video Intelligence",
    `Opening hook: ${video.openingHook}`,
    `Story timeline: ${video.storyTimeline}`,
    "Scenes:",
    ...video.scenes.map((s) => `- ${s}`),
    `Music mood: ${video.musicMood}`,
    `Voice tone: ${video.voiceTone}`,
    `Ending emotion: ${video.endingEmotion}`,
    `CTA: ${video.cta}`,
  ].join("\n");
}
