<?php

namespace App\Modules\Integrations\Platform\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @mixin \App\Modules\Integrations\Platform\Models\IntegrationWebhook
 */
class IntegrationWebhookResource extends JsonResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'url' => $this->url,
            'topics' => $this->topics,
            'is_active' => (bool) $this->is_active,
            'health_status' => $this->health_status,
            'last_success_at' => $this->last_success_at?->toISOString(),
            'last_failure_at' => $this->last_failure_at?->toISOString(),
            'failure_count' => (int) $this->failure_count,
            'created_at' => $this->created_at?->toISOString(),
            'updated_at' => $this->updated_at?->toISOString(),
        ];
    }
}
