<?php

// app/Models/BankIntegration.php

namespace App\Models;

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

class BankIntegration extends Model
{
    use HasFactory;

    protected $fillable = [
        'transaction_id', 'payment_id', 'type', 'amount', 'bank_code',
        'bank_response', 'status', 'error_message', 'processed_at',
    ];

    protected $casts = [
        'amount' => 'decimal:2',
        'bank_response' => 'array',
        'processed_at' => 'datetime',
    ];

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

    public function scopeSuccess($query)
    {
        return $query->where('status', 'success');
    }

    public function scopePending($query)
    {
        return $query->where('status', 'pending');
    }

    public function scopeFailed($query)
    {
        return $query->where('status', 'failed');
    }
}
