import type { SocialImageContext } from "@/lib/generation/social-image";
import { formatScenePlanForPrompt } from "@/lib/generation/scene-planner";

/**
 * Hero visual for SVG-composite fallback — driven by scene plan when available.
 * No typography (text/logo/CTA come from the branded template).
 */
export function buildHeroImagePrompt(ctx: SocialImageContext): string {
  const seed = ctx.layoutSeed ?? Date.now();
  const plan = ctx.scenePlan;
  const company = ctx.companyName || "the brand";
  const industry = ctx.industry || "B2B";
  const website = (ctx.website || ctx.brandStyle.website || "").replace(/^https?:\/\//i, "");
  const primary = ctx.primaryColor || ctx.brandStyle.primaryColor;
  const accent = ctx.accentColor || ctx.brandStyle.accentColor;
  const layout = plan?.layoutId ?? ctx.bannerLayoutId ?? "right_image";
  const isAdmissions =
    ctx.product?.solutionCategory === "education_admissions" ||
    plan?.industry === "education_admissions";

  const scene =
    plan?.sceneDescription ||
    "Premium 3D B2B storytelling still with document flows, network arcs, shields, and charts — not a generic office portrait.";
  const motifs = plan?.visualMotifs?.length
    ? plan.visualMotifs.join(", ")
    : "product-relevant tools, environment, and workflow cues";

  return [
    "# Premium Commercial Hero Image Brief",
    "",
    "Create a cinematic, photorealistic commercial HERO VISUAL ONLY.",
    "Square 1080×1080 framing suitable for website, LinkedIn, Facebook, YouTube, advertisements, presentations, and premium marketing materials.",
    "CRITICAL: NO text, NO letters, NO logos, NO wordmarks, NO brand names, NO watermarks, NO slogans, NO UI fake logos anywhere.",
    "Do not draw company names, node-network logo icons, or taglines — branding is added in post-production.",
    "",
    `Brand context: ${company}${website ? ` (${website})` : ""} — ${industry}.`,
    `Brand color accents (subtle): ${primary} and ${accent}.`,
    `Layout preference: ${layout}.`,
    `Unique variation token: ${seed}.`,
    "",
    plan ? formatScenePlanForPrompt(plan) : `Scene: ${scene}`,
    "",
    "## Creative direction",
    "Build the entire composition around ONE emotionally compelling hero moment. Avoid multiple competing stories.",
    "Capture the customer transition from challenge to confidence, clarity, or success through natural action—not text or infographic explanation.",
    "The image should communicate within three seconds why the customer values this product or service.",
    "Every subject, object, and environmental detail must reinforce the active product's value proposition.",
    "",
    "## Brand personality",
    "Premium, modern, human, approachable, confident, innovative, sophisticated, and trustworthy.",
    "The result should feel professionally art-directed for a leading global brand—not like generic AI or cheap stock photography.",
    "",
    "## Industry recognition",
    `Use recognizable visual cues from this specific story: ${motifs}.`,
    "Integrate cues naturally into the environment. Never substitute imagery from a keyword-adjacent industry.",
    "Do not use floating icon walls, decorative symbols, or fake dashboards unless the product genuinely requires an interface.",
    "",
    "## Human interaction",
    "People must look photorealistic, diverse, and contextually appropriate.",
    "Interactions should feel candid rather than posed: authentic expressions, believable eye contact, natural movement, purposeful collaboration, and confident body language.",
    "Use one dominant subject or interaction, supported by restrained secondary people and details.",
    "",
    "## Composition and marketing hierarchy",
    "Guide the viewer through: ATTENTION → EMOTION → STORY → TRUST → CONVERSION SPACE.",
    "Use unequal visual weight: one clear focal point, secondary supporting elements, and a quiet background.",
    "Create natural depth through foreground, middle ground, and background storytelling.",
    "Reserve approximately 30–40% clean negative space in the text side defined by the layout; keep faces and important objects out of that space.",
    "No brochure layout, infographic grid, feature-card wall, or equal emphasis on every object.",
    "",
    "## Photography and lighting",
    "High-end cinematic commercial photography with an editorial sensibility.",
    "Wide-angle, eye-level perspective; natural framing; shallow depth of field where appropriate.",
    "Soft natural sunlight or motivated cinematic light, HDR tonal range, realistic shadows, subtle reflections, atmospheric depth, and refined color grading.",
    "Photorealistic skin, hands, materials, architecture, devices, and environmental details.",
    "Premium global technology campaign, business editorial, and architectural/lifestyle advertising quality.",
    "",
    isAdmissions
      ? [
          "## Education admissions art direction (mandatory)",
          "Premium editorial EdTech / enterprise SaaS aesthetic inspired by Stripe, Notion, Linear, HubSpot, and Salesforce.",
          "Late-evening admissions office; counsellor coordinating search, WhatsApp, email, and website inquiries.",
          "Show an icon-based progression from inquiry to counselling, document verification, admission letter, visa, and enrolment — no generated text labels.",
          "Include parent trust, online student counselling, a modern international campus, and a subtle India-to-Uzbekistan map connection.",
          "Blue and white palette with restrained orange accents, glassmorphism, soft gradients, modern lighting, generous negative space.",
          "STRICTLY FORBIDDEN: doctors treating patients, hospital rooms, surgery, medical reports, clinical dashboards, random passport graphics, airplanes, visa stamps, crowded infographic walls, fake analytics, cartoon clip-art.",
        ].join("\n")
      : "",
    "",
    "Render the scene above as the hero illustration.",
    "",
    "## Negative constraints",
    "Avoid cartoons, anime, illustration, low quality, blur, pixelation, distorted faces, poor anatomy, extra fingers/limbs, duplicate people, fake smiles, watermarks, random text, fake logos, misspellings, oversaturated colors, harsh lighting, noisy backgrounds, clutter, excessive floating UI, cheap stock-photo appearance, and obvious AI artifacts.",
    "",
    "Final result: clean, timeless, emotionally engaging, photorealistic commercial artwork with a strong customer story and intentional whitespace for deterministic branding and copy overlays.",
  ].join("\n");
}
