"""
Shared prompt templates for single-choice MCQ evaluation.
"""
from __future__ import annotations


_MUST_GUESS_RULES = (
    'Rules:\n'
    '- You MUST answer with one of the choices. If uncertain, make your best '
    'guess based on the available information and your prior knowledge.\n'
    '- Do NOT refuse, do NOT ask for clarification, do NOT explain your reasoning '
    'in the response. Output ONLY the format specified below — nothing else.'
)


def mcq_prompt_json(row: dict, *, header: str = '') -> str:
    """JSON-output MCQ prompt for instruction-tuned models."""
    head = (header.rstrip() + '\n\n') if header else ''
    return (
        f'{head}'
        f"Question: {row['question']} Select the single best choice.\n"
        f"A: {row['option_A']}\n"
        f"B: {row['option_B']}\n"
        f"C: {row['option_C']}\n"
        f"D: {row['option_D']}\n\n"
        f'{_MUST_GUESS_RULES}\n\n'
        f'Output ONLY valid JSON in this exact format:\n'
        f'  {{"id": {row["qid"]}, "answer": "X"}}'
    )


def mcq_prompt_letters(row: dict, *, header: str = '') -> str:
    """Letters-only fallback for VLMs that don't reliably emit JSON."""
    head = (header.rstrip() + '\n\n') if header else ''
    return (
        f'{head}'
        f"Question: {row['question']}\n"
        f"A. {row['option_A']}\n"
        f"B. {row['option_B']}\n"
        f"C. {row['option_C']}\n"
        f"D. {row['option_D']}\n\n"
        f'{_MUST_GUESS_RULES}\n\n'
        f'Reply with ONLY a single letter from A/B/C/D. Example: A'
    )


HEADER_VIDEO_FRAMES = (
    'The above {n_frames} images are uniformly sampled frames from a full-length movie. '
    'Watch them carefully and answer the question below.'
)

HEADER_VIDEO_CLIP = (
    'The above is a full-length movie. '
    'Watch it carefully and answer the question below.'
)

HEADER_TEXT_ONLY = (
    'No video or images are provided. Answer the question below using only your '
    'prior knowledge of films and the information in the question itself. If you '
    'do not recognize the specific film, infer from the question and choices and '
    'commit to the single most plausible guess.'
)

HEADER_WORLD_STATE = (
    'Below is a detailed chronological description of a movie, followed by a question. '
    'Answer based ONLY on the description. If the description is incomplete, commit '
    'to the most plausible answer rather than refusing.\n\n'
    '## MOVIE DESCRIPTION\n{wsh}\n'
)

HEADER_SUBTITLES_ONLY = (
    'Below are the subtitles from a movie — automatically transcribed dialogue '
    'and any speaker / sound annotations the transcriber emitted. There is no '
    'description of action, setting, or non-verbal events beyond what is in '
    'the subtitles. Answer based ONLY on this text. If the subtitles do not '
    'contain the information needed, commit to the most plausible answer '
    'rather than refusing.\n\n'
    '## SUBTITLES\n{subtitles}\n'
)


BASE_CAPTION_PROMPT = (
    'Describe this video segment in detail. Include: '
    'the setting and environment, characters present and their appearances, '
    'actions and interactions, any dialogue or spoken content, '
    'camera movements and shot types, and the overall mood or tone.'
)

BASE_CAPTION_PROMPT_AUDIO = (
    'Describe this video segment in detail. Include: '
    'the setting and environment, characters present, '
    'actions and interactions, dialogue (transcribe or paraphrase spoken lines), '
    'sound effects, music, ambient sounds, '
    'camera movements and shot types, and the overall mood.'
)
