import type { ImageRequest } from "./GrokBridge.js";

/**
 * Reference-sheet prompt templates.
 *
 * The analysis stage measures a silhouette, so the prompt is engineered for
 * *measurability* rather than beauty: a plain background it can flood-fill
 * away, flat lighting so shadows do not read as body mass, limbs held clear of
 * the torso so the row-width profile can separate them, and the whole figure
 * inside frame so no landmark is cropped.
 */

export interface CharacterPromptOptions {
  /** Free-form description: "a lone survivor in a heavy canvas jacket". */
  description: string;
  /** Held clear of the body so arms and torso separate in the silhouette. */
  pose?: "a-pose" | "t-pose";
}

const MEASURABILITY_CLAUSE =
  "Flat, even, shadowless lighting. Plain uniform neutral grey background with nothing else in frame. " +
  "The entire body is visible from the top of the head to the soles of the boots, with clear space " +
  "above and below. Straight-on front view, camera at chest height, no perspective foreshortening. " +
  "No text, no labels, no props on the ground, no cast shadow.";

export function characterReferencePrompt(options: CharacterPromptOptions): ImageRequest {
  const pose =
    options.pose === "t-pose"
      ? "standing in a symmetrical T-pose with both arms straight out horizontally at shoulder height, " +
        "legs straight and slightly apart, palms down"
      : "standing in a symmetrical A-pose with both arms held down and away from the body at about " +
        "45 degrees, clear of the torso, legs straight and slightly apart";

  return {
    prompt: `Full-body character reference sheet. ${options.description}, ${pose}. ${MEASURABILITY_CLAUSE} Low-poly PSX-era survival horror video game character art, muted desaturated palette, strong readable silhouette.`,
    aspectRatio: "3:4",
  };
}

/**
 * Variation of an existing character, for a cast that shares proportions.
 * Uses `image_edit` so the silhouette stays measurable and consistent.
 */
export function characterVariantPrompt(
  sourceImage: string,
  change: string,
): ImageRequest {
  return {
    prompt: `${change}. Keep the exact same pose, framing, body proportions, camera angle, flat lighting and plain grey background.`,
    sourceImages: [sourceImage],
    aspectRatio: "3:4",
  };
}

/** Prop/item reference — GDD §10.1's secondary pipeline. */
export function propReferencePrompt(description: string): ImageRequest {
  return {
    prompt: `A single ${description}, isolated product shot, centred in frame, straight-on side view. ${MEASURABILITY_CLAUSE} Low-poly PSX-era survival horror game asset, muted palette.`,
    aspectRatio: "1:1",
  };
}
