# retoor <retoor@molodetz.nl>

from __future__ import annotations

from ..spec import Action
from ._shared import body, confirm, path, query

BATTLE_ACTIONS: tuple[Action, ...] = (
    Action(
        name="list_battles",
        method="GET",
        path="/battles",
        summary="List Opinion War battles",
        description=(
            "Returns week-long two-faction battles attached to posts, with HP totals, "
            "percentages, top contributors and the viewer's own faction state."
        ),
        handler="http",
        requires_auth=False,
        read_only=True,
        params=(
            query("search", "Match a faction name or the creator's username."),
            query("filter", "One of active, ended, mine. Defaults to active."),
            query("page", "1-based page number."),
        ),
    ),
    Action(
        name="get_battle",
        method="GET",
        path="/battles/{uid}",
        summary="Get one Opinion War battle's full state",
        handler="http",
        requires_auth=False,
        read_only=True,
        params=(path("uid", "Battle uid."),),
    ),
    Action(
        name="battle_events",
        method="GET",
        path="/battles/{uid}/events",
        summary="Read a battle's event log",
        description=(
            "Ordered battle events (join, switch, fight, lead_change, result). Pass "
            "after to replay incrementally from a sequence number."
        ),
        handler="http",
        requires_auth=False,
        read_only=True,
        params=(
            path("uid", "Battle uid."),
            query("after", "Return only events with a seq greater than this."),
            query("limit", "Maximum events to return."),
        ),
    ),
    Action(
        name="join_battle",
        method="POST",
        path="/battles/{uid}/join",
        summary="Join or switch to a faction in an Opinion War",
        description=(
            "Joins faction a or b, or switches an existing fighter to the other side. "
            "Damage already dealt stays with the faction it was dealt to."
        ),
        handler="http",
        requires_auth=True,
        params=(
            path("uid", "Battle uid."),
            body("faction", "Which side to join or switch to: a or b.", required=True),
            confirm(),
        ),
    ),
    Action(
        name="fight_battle",
        method="POST",
        path="/battles/{uid}/fight",
        summary="Fight for your faction in an Opinion War",
        description=(
            "Spends 25 Code Farm coins and deals level-weighted HP damage for the "
            "fighter's faction. Allowed once per 24 hours per battle."
        ),
        handler="http",
        requires_auth=True,
        params=(path("uid", "Battle uid."), confirm()),
    ),
)
