<?php

declare(strict_types=1);

$base = 'http://karviapi1.de';
$id = '1';
$paths = [
    ['PUT', "/karvipartner/contracts/{$id}"],
    ['PATCH', "/karvipartner/contracts/{$id}"],
    ['GET', "/karvipartner/contracts/{$id}"],
    ['POST', "/karvipartner/contracts/{$id}/duplicate"],
    ['POST', '/karvipartner/contracts/duplicate'],
    ['POST', "/karvipartner/contracts/duplicate/{$id}"],
];

foreach ($paths as [$method, $path]) {
    $ch = curl_init($base . $path);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 12,
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_HTTPHEADER => ['Accept: application/json', 'Content-Type: application/json'],
        CURLOPT_POSTFIELDS => json_encode(['raw_data' => ['pdf_viewed_at' => date('c')]]),
    ]);
    $raw = curl_exec($ch);
    $status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    $d = is_string($raw) ? json_decode($raw, true) : null;
    $msg = is_array($d) ? (string)($d['message'] ?? '') : '';
    echo sprintf("%-6s %-40s HTTP %3d  %s\n", $method, $path, $status, $msg);
}
