import type { BrandProfile, Project } from "@/types/workflow";
import { getStoryArcForProject } from "../story-context-builder";
import {
  buildStoryIntelligence,
  formatStoryIntelligenceMarkdown,
} from "../intelligence/story-intelligence";

/** Story Intelligence from arc beat + Letter to God anchor. */
export function buildSequenceStoryContext(
  brand: BrandProfile,
  project: Project,
  beatIndex: number,
) {
  const arc = getStoryArcForProject(brand, project);
  const beat = arc[beatIndex] ?? arc[0];
  if (!beat) {
    throw new Error("Story arc has no beats for this project.");
  }

  const intelligence = buildStoryIntelligence(beat, beatIndex, arc.length);
  return {
    beat,
    intelligence,
    markdown: formatStoryIntelligenceMarkdown(intelligence),
  };
}
