<?php

namespace App\Models;

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

class PayFastPayment extends Model
{
    use HasFactory;

    protected $table = 'payfast_payments';

    protected $fillable = [
        'user_id',
        'invoice_id',
        'whmcs_invoice_id',
        'basket_id',
        'transaction_id',
        'expected_amount',
        'expected_currency',
        'invoice_amount',
        'invoice_currency',
        'conversion_rate',
        'whmcs_currency_id',
        'currency_snapshot',
        'callback_amount',
        'merchant_amount',
        'callback_currency',
        'order_date',
        'signature',
        'mode',
        'gateway',
        'status',
        'payfast_error_code',
        'payfast_error_message',
        'validation_hash',
        'callback_payload',
        'callback_received_at',
        'verified_at',
        'whmcs_synced_at',
        'sync_attempts',
        'next_retry_at',
        'last_error',
    ];

    protected $casts = [
        'expected_amount' => 'decimal:2',
        'invoice_amount' => 'decimal:2',
        'conversion_rate' => 'decimal:8',
        'whmcs_currency_id' => 'integer',
        'currency_snapshot' => 'array',
        'callback_amount' => 'decimal:2',
        'merchant_amount' => 'decimal:2',
        'order_date' => 'datetime',
        'callback_payload' => 'array',
        'callback_received_at' => 'datetime',
        'verified_at' => 'datetime',
        'whmcs_synced_at' => 'datetime',
        'next_retry_at' => 'datetime',
        'sync_attempts' => 'integer',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function invoice()
    {
        return $this->belongsTo(Invoice::class);
    }
}
