<<?php
declare(strict_types=1);
header("Content-Type: application/json; charset=utf-8");

$hook = "https://hooks.zapier.com/hooks/catch/26263680/uls9sxe/";

$payload = [
  "request_id"   => "test_" . uniqid(),
  "event"        => "published",
  "region"       => "US",
  "content_type" => "image", // image | video | text

  "title"        => "Zapier Test Post (SMM)",
  "url"          => "https://example.com/test-post",

  "caption"      => "Zapier test ✅ #automation #socialmedia #yoga",
  "hashtags"     => ["#automation", "#socialmedia", "#yoga"],

  // Put real URLs if you want to test actual publishing:
  "image_url"    => "https://picsum.photos/seed/zaptest/1080/1080",
  "video_url"    => ""
];

$json = json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

$ch = curl_init($hook);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Content-Type: application/json",
  "Content-Length: " . strlen($json)
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_TIMEOUT, 25);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);

$out  = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err  = curl_error($ch);
curl_close($ch);

echo json_encode([
  "ok" => ($out !== false && $code < 400),
  "http_code" => $code,
  "curl_error" => $err,
  "zapier_response" => substr((string)$out, 0, 300),
  "sent" => $payload
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
