# retoor <retoor@molodetz.nl>

from __future__ import annotations

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


POSTS_ACTIONS: tuple[Action, ...] = (
    Action(
        name="view_feed",
        method="GET",
        path="/feed",
        summary="View the activity feed",
        requires_auth=False,
        params=(
            query("tab", "Feed tab to view."),
            query("topic", "Filter by topic."),
            query("search", "Search post title, content, and author username."),
            query("before", "Pagination cursor."),
        ),
    ),
    Action(
        name="view_topics",
        method="GET",
        path="/topics",
        summary="View the topics hub - every post topic with its live post count",
        requires_auth=False,
        params=(),
    ),
    Action(
        name="view_topic",
        method="GET",
        path="/topics/{topic}",
        summary="View one topic's post listing (e.g. devlog, showcase, question, rant, fun, random, politics)",
        requires_auth=False,
        params=(
            path("topic", "Topic key, one of the values TOPICS lists."),
            query("before", "Pagination cursor."),
        ),
    ),
    Action(
        name="create_post",
        method="POST",
        path="/posts/create",
        summary="Create a new post",
        params=(
            body("content", "Post body text.", required=True),
            body("title", "Optional post title."),
            body("topic", "Optional topic."),
            body("project_uid", "Attach the post to a project uid."),
            body("attachment_uids", ATTACHMENTS),
            body("poll_question", "Optional poll question."),
            body(
                "poll_options",
                "Poll options as a JSON array of strings, or one option per line, or comma separated. At least two are required for the poll to be created.",
            ),
            body(
                "war_faction_a",
                "Optional Opinion War faction A name (max 30 chars). Both faction names are required to start the week-long battle.",
            ),
            body(
                "war_faction_b",
                "Optional Opinion War faction B name (max 30 chars). Must differ from faction A.",
            ),
        ),
    ),
    Action(
        name="view_post",
        method="GET",
        path="/posts/{post_slug}",
        summary="View a single post by slug",
        requires_auth=False,
        params=(
            path(
                "post_slug",
                "Exact post slug copied from a /posts/... link in a feed or listing response; do not build it from the title.",
            ),
        ),
    ),
    Action(
        name="edit_post",
        method="POST",
        path="/posts/edit/{post_slug}",
        summary="Edit an existing post",
        params=(
            path(
                "post_slug",
                "Exact post slug copied from a /posts/... link in a feed or listing response; do not build it from the title.",
            ),
            body("content", "Updated post body.", required=True),
            body("title", "Updated title."),
            body("topic", "Updated topic."),
            body(
                "poll_question",
                "Optional poll question. Adds a poll to a post that does not already have one.",
            ),
            body(
                "poll_options",
                "Poll options as a JSON array of strings, or one option per line, or comma separated. At least two are required for the poll to be created.",
            ),
        ),
    ),
    Action(
        name="delete_post",
        method="POST",
        path="/posts/delete/{post_slug}",
        summary="Delete a post (your own, or any post when you are an administrator). Soft delete, confirmation required",
        params=(
            path(
                "post_slug",
                "Exact post slug copied from a /posts/... link in a feed or listing response; do not build it from the title.",
            ),
            confirm(),
        ),
    ),
)
