<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * @property int $id
 * @property int|null $payment_id
 * @property string $provider
 * @property string|null $hook_id
 * @property string|null $event
 * @property string|null $account_id
 * @property string|null $order_id
 * @property string|null $charge_id
 * @property string|null $transaction_id
 * @property string $status
 * @property int $attempts_count
 * @property array<array-key, mixed> $payload
 * @property \Illuminate\Support\Carbon|null $received_at
 * @property \Illuminate\Support\Carbon|null $processed_at
 * @property string|null $error_message
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\Payment|null $payment
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereAccountId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereAttemptsCount($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereChargeId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereErrorMessage($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereEvent($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereHookId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook wherePayload($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook wherePaymentId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereProcessedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereProvider($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereReceivedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereTransactionId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Webhook whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Webhook extends Model
{
    use HasFactory;

    protected $table = 'webhooks';

    protected $fillable = [
        'payment_id',
        'provider',
        'hook_id',
        'event',
        'account_id',
        'order_id',
        'charge_id',
        'transaction_id',
        'status',
        'attempts_count',
        'payload',
        'received_at',
        'processed_at',
        'error_message',
    ];

    protected $casts = [
        'attempts_count' => 'integer',
        'payload'        => 'array',
        'received_at'    => 'datetime',
        'processed_at'   => 'datetime',
        'created_at'     => 'datetime',
        'updated_at'     => 'datetime',
    ];

    public function payment()
    {
        return $this->belongsTo(Payment::class);
    }
}
