<?php
/**
 * Tool: swap_or_add_image (v1: stub)
 *
 * The full implementation needs a media-picker UX in the rail (open WP's
 * wp.media() modal, capture attachment ID, finish the swap server-side).
 * That arrives in the next sprint. For v1 we return a clear, honest result
 * so Claude can explain to the user what to do in the meantime — no false
 * promises, no half-built UX.
 */
if (!defined('ABSPATH')) exit;

function swcp_tool_swap_or_add_image($input, $ctx) {
    $page_arg = isset($input['page']) ? $input['page'] : 'current';
    $action   = isset($input['action']) ? $input['action'] : 'swap';
    $resolved = swcp_resolve_or_error($page_arg, $ctx['post_id'] ?? 0);
    if (is_array($resolved) && isset($resolved['ok']) && !$resolved['ok']) return $resolved;
    $post = $resolved;

    return [
        'ok'         => false,
        'pending'    => true,
        'message'    => 'Image ' . ($action === 'add' ? 'add' : 'swap') . ' is not wired up in this version of SailWP Co-pilot yet. The visual media picker arrives in the next update. For now, you can change images directly from the WordPress media library on the page edit screen.',
        'page_id'    => $post->ID,
        'edit_url'   => swcp_edit_url_for($post->ID),
    ];
}
