<?php

namespace App\Http\Controllers\Api\Channels;

use App\Domains\Channels\Models\WebhookEvent;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

class WebhookEventShowController extends Controller
{
    public function __invoke(string $event): JsonResponse
    {
        $record = WebhookEvent::query()->findOrFail($event);

        return response()->json([
            'data' => [
                'id' => $record->id,
                'source' => $record->source,
                'eventType' => $record->event_type,
                'status' => $record->processing_status,
                'errorMessage' => $record->error_message,
                'retriesCount' => $record->retries_count,
                'processedAt' => $record->processed_at?->format('M d, H:i'),
                'createdAt' => $record->created_at?->format('M d, H:i'),
                'payload' => $record->payload_json,
            ],
        ]);
    }
}
