import type { PlatformIntelligence } from "./types";

const PLATFORM_DEFAULTS: PlatformIntelligence[] = [
  {
    platform: "linkedin",
    tone: "Professional, thought leadership",
    format: "Long-form narrative, bold hook, 250-400 words",
    strengths: ["B2B trust", "Industry discussion", "Founder/operator stories"],
  },
  {
    platform: "facebook",
    tone: "Community, relatable",
    format: "Same caption as LinkedIn — discussion-friendly close",
    strengths: ["Local business", "Community engagement", "Shareable stories"],
  },
  {
    platform: "instagram",
    tone: "Visual, emotional",
    format: "Caption from master text; image carries mood",
    strengths: ["Brand personality", "Behind-the-scenes feel", "Emotional hooks"],
  },
  {
    platform: "youtube",
    tone: "Educational, story-driven",
    format: "Description from caption; video follows story timeline",
    strengths: ["Deeper explanation", "Slideshow narrative", "Searchable descriptions"],
  },
  {
    platform: "x",
    tone: "Fast, opinion-led",
    format: "Condensed hook + insight (future)",
    strengths: ["Hot takes", "Quick engagement", "Thread potential"],
  },
];

export function buildPlatformIntelligence(
  connectedPlatforms?: string[],
): PlatformIntelligence[] {
  if (!connectedPlatforms?.length) return PLATFORM_DEFAULTS;

  const normalized = connectedPlatforms.map((p) => p.toLowerCase());
  const selected = PLATFORM_DEFAULTS.filter((p) => normalized.includes(p.platform));
  return selected.length ? selected : PLATFORM_DEFAULTS;
}

export function formatPlatformIntelligenceMarkdown(platforms: PlatformIntelligence[]): string {
  return [
    "## Platform Intelligence",
    ...platforms.flatMap((p) => [
      `### ${p.platform}`,
      `Tone: ${p.tone}`,
      `Format: ${p.format}`,
      `Strengths: ${p.strengths.join(", ")}`,
      "",
    ]),
  ].join("\n");
}
