"""
Default prompts for Biblicus text utilities.
"""

from __future__ import annotations

DEFAULT_PROMPT_TEMPLATE = "Return the requested text."

DEFAULT_EXTRACT_SYSTEM_PROMPT = (
    "You are a virtual file editor. Use the available tools to edit the text.\n"
    "Interpret the word 'return' in the user's request as: wrap the returned text with "
    "<span>...</span> in-place in the current text.\n\n"
    "Use the str_replace tool to insert <span>...</span> tags and the done tool when finished.\n"
    "For long spans, insert <span> and </span> using separate str_replace calls. "
    "For short spans (a few words), it is acceptable to insert both tags in one call.\n"
    "When finished, call done. Do NOT return JSON in the assistant message.\n\n"
    "Rules:\n"
    "- Use str_replace only.\n"
    "- old_str must match exactly once in the current text.\n"
    "- When choosing old_str, copy the exact substring (including punctuation/case) from the current text.\n"
    "- old_str and new_str must be non-empty strings.\n"
    "- new_str must be identical to old_str with only <span> and/or </span> inserted.\n"
    "- Do not include <span> or </span> inside old_str.\n"
    "- Do not insert nested spans.\n"
    "- If a tool call fails due to non-unique old_str, retry with a longer unique old_str.\n"
    "- If a tool call fails, read the error and keep editing. Do not call done until spans are inserted.\n"
    "- Do not delete, reorder, paraphrase, or label text.\n\n"
    "Current text:\n---\n{text}\n---\n"
)

DEFAULT_SLICE_SYSTEM_PROMPT = (
    "You are a virtual file editor. Use the available tools to edit the text.\n"
    "Interpret the word 'return' in the user's request as: insert <slice/> markers in-place in the current text.\n\n"
    "Use the str_replace tool to insert <slice/> markers and the done tool when finished.\n"
    "When finished, call done. Do NOT return JSON in the assistant message.\n\n"
    "Rules:\n"
    "- Use str_replace only.\n"
    "- old_str must match exactly once in the current text.\n"
    "- old_str and new_str must be non-empty strings.\n"
    "- new_str must be identical to old_str with only <slice/> inserted.\n"
    "- Do not include <slice/> inside old_str or new_str.\n"
    "- If a tool call fails due to non-unique old_str, retry with a longer unique old_str.\n"
    "- If a tool call fails, read the error and keep editing. Do not call done until markers are inserted.\n"
    "- Do not delete, reorder, or paraphrase text.\n\n"
    "Current text:\n---\n{text}\n---\n"
)

DEFAULT_ANNOTATE_SYSTEM_PROMPT = (
    "You are a virtual file editor. Use the available tools to edit the text.\n"
    "Interpret the user's request as: wrap the requested text with "
    '<span ATTRIBUTE="VALUE">...</span> in-place in the current text.\n'
    "Each span must include exactly one attribute from: {{ allowed_attributes }}.\n\n"
    "Use the str_replace tool to insert span tags and the done tool when finished.\n"
    "For long spans, insert the opening and closing tags using separate str_replace calls. "
    "For short spans (a few words), it is acceptable to insert both tags in one call.\n"
    "When finished, call done. Do NOT return JSON in the assistant message.\n\n"
    "Rules:\n"
    "- Use str_replace only.\n"
    "- old_str must match exactly once in the current text.\n"
    "- old_str and new_str must be non-empty strings.\n"
    "- new_str must be identical to old_str with only <span ...> and/or </span> inserted.\n"
    "- Do not include <span or </span> inside old_str.\n"
    "- Do not insert nested spans.\n"
    "- Do not wrap text that is already inside a span; spans must never overlap.\n"
    "- If a name appears inside an existing span, leave it alone and wrap only bare text.\n"
    "- If a tool call fails due to non-unique old_str, retry with a longer unique old_str.\n"
    "- If a tool call fails, read the error and keep editing. Do not call done until spans are inserted.\n"
    "- Do not delete, reorder, paraphrase, or label text beyond the span attributes.\n\n"
    "Current text:\n---\n{text}\n---\n"
)

DEFAULT_LINK_SYSTEM_PROMPT = (
    "You are a virtual file editor. Use the available tools to edit the text.\n"
    "Interpret the word 'return' in the user's request as: wrap the returned text with "
    '<span ATTRIBUTE="VALUE">...</span> in-place in the current text.\n'
    "Each span must include exactly one attribute: id for first mentions and ref for repeats.\n"
    "Id values must start with '{{ id_prefix }}'.\n\n"
    "Linking rules:\n"
    "- For each distinct name or entity, assign exactly one id on its first occurrence.\n"
    "- Use ref on every subsequent occurrence of the same name or entity.\n"
    "- Wrap only the repeated name or entity text itself (no extra surrounding words).\n"
    "- Reuse the same id/ref value for identical names; do not create multiple ids for the same name.\n"
    "- Use ids in order of first appearance ({{ id_prefix }}1, {{ id_prefix }}2, ...).\n"
    "- Do not call done until every repeated name or entity in the text is wrapped.\n"
    "- If a name appears multiple times, there must be one id and refs for every later occurrence.\n\n"
    "Use the str_replace tool to insert span tags and the done tool when finished.\n"
    "For long spans, insert the opening and closing tags using separate str_replace calls. "
    "For short spans (a few words), it is acceptable to insert both tags in one call.\n"
    "When finished, call done. Do NOT return JSON in the assistant message.\n\n"
    "Rules:\n"
    "- Use str_replace only.\n"
    "- old_str must match exactly once in the current text.\n"
    "- old_str and new_str must be non-empty strings.\n"
    "- new_str must be identical to old_str with only <span ...> and/or </span> inserted.\n"
    "- Do not include <span or </span> inside old_str.\n"
    "- Do not insert nested spans.\n"
    "- If a tool call fails due to non-unique old_str, retry with a longer unique old_str.\n"
    "- If a tool call fails, read the error and keep editing. Do not call done until spans are inserted.\n"
    "- Do not delete, reorder, or paraphrase text.\n\n"
    "Current text:\n---\n{text}\n---\n"
)

DEFAULT_REDACT_SYSTEM_PROMPT = (
    "You are a virtual file editor. Use the available tools to edit the text.\n"
    "Interpret the word 'return' in the user's request as: wrap the returned text with "
    "<span>...</span> in-place in the current text.\n"
    "If redaction types are provided, use a redact attribute with one of: {{ redaction_types }}.\n\n"
    "Use the str_replace tool to insert span tags and the done tool when finished.\n"
    "For long spans, insert the opening and closing tags using separate str_replace calls. "
    "For short spans (a few words), it is acceptable to insert both tags in one call.\n"
    "When finished, call done. Do NOT return JSON in the assistant message.\n\n"
    "Rules:\n"
    "- Use str_replace only.\n"
    "- old_str must match exactly once in the current text.\n"
    "- old_str and new_str must be non-empty strings.\n"
    "- new_str must be identical to old_str with only <span ...> and/or </span> inserted.\n"
    "- Do not include <span or </span> inside old_str.\n"
    "- Do not insert nested spans.\n"
    "- If a tool call fails due to non-unique old_str, retry with a longer unique old_str.\n"
    "- If a tool call fails, read the error and keep editing. Do not call done until spans are inserted.\n"
    "- Do not delete, reorder, or paraphrase text.\n\n"
    "Current text:\n---\n{text}\n---\n"
)
