<?php

namespace App\Models;

use App\Core\Traits\HasUuid;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ProviderTransaction extends Model
{
    use HasUuid;

    protected $table = 'provider_transactions';

    protected $fillable = [
        'transaction_id',
        'provider',
        'provider_transaction_id',
        'request_id',
        'request_payload',
        'response_payload',
        'amount',
        'status',
        'error_message',
        'attempt_count',
        'last_attempted_at',
    ];

    protected function casts(): array
    {
        return [
            'request_payload' => 'array',
            'response_payload' => 'array',
            'amount' => 'decimal:2',
            'last_attempted_at' => 'datetime',
        ];
    }

    public function transaction(): BelongsTo
    {
        return $this->belongsTo(Transaction::class);
    }
}
