import type { GameFacts } from './types';

// These prompts are the actual anti-spam mechanism, not just the styling
// mechanism. Three things are enforced here on purpose:
//  1. Grounding — write only from the supplied facts; general genre
//     knowledge is fine, invented specifics are not.
//  2. Originality — no source text is ever pasted into the prompt for the
//     model to paraphrase; it only sees structured facts (names, dates,
//     numbers), so there's nothing to closely reword in the first place.
//  3. Honesty over padding — thin facts should produce short, honest
//     sections, not confident-sounding filler. The quality gate in
//     qualityGate.ts is the second layer of defense against filler that
//     gets through anyway.

export const CONTENT_SYSTEM_PROMPT = `You are a reference editor for a gaming knowledge site. You write clear, original, genuinely useful game pages for players — not content designed to rank in search engines.

Hard rules:
- Use ONLY the facts given to you in the game data block. You may add general, genre-level knowledge (e.g. "like most battle royale games, early positioning matters") but never invent specific facts about THIS game — no invented characters, weapons, maps, patch details, or numeric stats that were not provided.
- If the provided facts are too thin to support a genuinely useful section, write a short, honest section that says what's known and does not pad with generic filler. A short accurate section beats a long vague one.
- Never write as if you're addressing a search engine. Never mention SEO, rankings, or keywords in the content itself.
- Write in your own words. Do not mirror any external source's sentence structure — you have not been given any source text to paraphrase, only structured facts, so this should be natural.
- No marketing hype ("revolutionary", "must-play", "changing gaming forever"). Write like a knowledgeable, plainspoken player.
- Output must be valid JSON matching the requested schema exactly, via the provided tool. No prose outside the tool call.`;

export function buildGameContentPrompt(facts: GameFacts): string {
  const releaseYear = facts.releaseDate ? new Date(facts.releaseDate).getFullYear() : 'unknown';

  return `Write original page content for this game using only the facts below.

GAME DATA:
- Name: ${facts.name}
- Release date: ${facts.releaseDate ?? 'unknown'} (${releaseYear})
- Genres: ${facts.genres.join(', ') || 'unknown'}
- Platforms: ${facts.platforms.join(', ') || 'unknown'}
- Developers: ${facts.developers.join(', ') || 'unknown'}
- Publishers: ${facts.publishers.join(', ') || 'unknown'}
- Game modes: ${facts.gameModes.join(', ') || 'unknown'}
- Age rating: ${facts.ageRating ?? 'unrated / unknown'}
- Aggregated rating: ${facts.rating != null ? `${facts.rating}/100 from ${facts.ratingCount ?? 0} ratings` : 'not enough ratings yet'}
- Official summary (factual source, IGDB/RAWG): ${facts.summary ?? 'none provided'}
- Storyline (if provided): ${facts.storyline ?? 'none provided'}
- Recent news headlines (for the "Latest Updates" context only — reference the fact that these things happened, do not repeat the headline text verbatim): ${
    facts.recentNewsHeadlines.length > 0 ? facts.recentNewsHeadlines.join(' | ') : 'none available'
  }

Produce these fields via the save_game_content tool:
- overview: 2-3 paragraphs, what the game is and why someone would care.
- gameplay: 1-2 paragraphs on core gameplay loop, grounded in genre + provided facts.
- features: 4-8 concrete bullet points (as a single string with line breaks), specific to what's known.
- tipsAndTricks: genre-appropriate general guidance for new players. Do not invent game-specific mechanics you were not given.
- beginnerGuide: short paragraph on how to get started (platforms, modes, what to expect first).
- howToPlay: short paragraph — controls/structure at a general level appropriate to the genre and platform, without inventing specific control schemes not provided.
- alternatives: 1 short paragraph naming the KIND of game this is similar to (by genre/mechanics), not invented named titles unless genuinely well-known genre siblings.
- faqs: 4-6 question/answer pairs a real player would search for, answered only from the facts given.
- pros: 3-5 short bullet points.
- cons: 2-4 short bullet points — honest limitations (e.g. platform availability, age of last update, rating volume), not invented flaws.
- metaTitle: under 60 characters, includes the game name.
- metaDescription: under 155 characters, factual and specific.
- keywords: 6-10 relevant search terms.

If a section would require inventing details you don't have, keep it short and general rather than fabricating specifics.`;
}
