#!/bin/bash

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Reeling Quick Post & Spam Check
# @raycast.mode fullOutput
# @raycast.packageName Reeling
#
# Optional parameters:
# @raycast.icon 🎬
# @raycast.argument1 { "type": "text", "placeholder": "Platform (reddit, quora, x, linkedin, bluesky)" }
# @raycast.argument2 { "type": "text", "placeholder": "Title / Hook" }
# @raycast.argument3 { "type": "text", "placeholder": "Post Body / Caption" }
#
# Documentation:
# @raycast.description Schedule or queue a social post via the Reeling v1 API with built-in Spam Shield checks.
# @raycast.author Reeling
# @raycast.authorURL https://reeling.app/plugins/raycast

if [ -z "$REELING_API_KEY" ] || [ -z "$REELING_PROJECT_ID" ]; then
  echo "Set REELING_API_KEY and REELING_PROJECT_ID in your environment first."
  echo "Get your API key at: https://reeling.app/settings?tab=api"
  exit 1
fi

PLATFORM="$1"
TITLE="$2"
CAPTION="$3"

curl -sS -X POST "https://api.reeling.app/api/v1/publish" \
  -H "X-API-Key: $REELING_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq -n \
    --arg pid "$REELING_PROJECT_ID" \
    --arg platform "$PLATFORM" \
    --arg title "$TITLE" \
    --arg caption "$CAPTION" \
    '{project_id: $pid, platforms: [$platform], title: $title, caption: $caption}')" | jq .
