# retoor <retoor@molodetz.nl>

from __future__ import annotations

from .spec import Action, Param


def arg(
    name: str, description: str, required: bool = False, kind: str = "string"
) -> Param:
    return Param(
        name=name,
        location="body",
        description=description,
        required=required,
        type=kind,
    )


AI_CORRECTION_ACTIONS: tuple[Action, ...] = (
    Action(
        name="ai_correction_get",
        method="LOCAL",
        path="",
        summary="Show the user's AI content correction setting and prompt",
        description=(
            "Returns whether automatic AI content correction is enabled for the user and the "
            "correction instruction in use. Use this before changing the setting."
        ),
        handler="ai_correction",
        requires_auth=True,
        read_only=True,
    ),
    Action(
        name="ai_correction_set",
        method="LOCAL",
        path="",
        summary="Enable or disable AI content correction and set its prompt",
        description=(
            "Turns automatic AI content correction on or off for the user. When enabled, prose the "
            "user authors (posts, comments, projects, gists, direct messages, profile bio) is "
            "rewritten using the supplied instruction and the user's own API key. By default the "
            "correction runs in the background (applied just after saving); pass sync=true to apply it "
            "synchronously so the save waits for the correction. "
            "Pass 'prompt' to change the correction instruction; omit it to keep the current one."
        ),
        handler="ai_correction",
        requires_auth=True,
        params=(
            arg(
                "enabled",
                "true to enable automatic correction, false to disable it.",
                required=True,
                kind="boolean",
            ),
            arg(
                "sync",
                "true to apply correction synchronously (the save waits), false for background. "
                "Omit to keep the current mode.",
                kind="boolean",
            ),
            arg(
                "prompt",
                "The correction instruction (max 20000 chars). Omit to keep the current one.",
            ),
        ),
    ),
)
