<?php

namespace App\Models;

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

class WalletTransaction extends Model
{
    use HasFactory;

    protected $fillable = [
        'wallet_id',
        'user_id',
        'type',
        'source',
        'amount',
        'balance_before',
        'balance_after',
        'reference_type',
        'reference_id',
        'description',
        'notes',
        'status',
    ];

    protected $casts = [
        'amount' => 'decimal:2',
        'balance_before' => 'decimal:2',
        'balance_after' => 'decimal:2',
    ];

    /**
     * المحفظة المرتبطة بهذه المعاملة
     */
    public function wallet()
    {
        return $this->belongsTo(Wallet::class);
    }

    /**
     * المستخدم المالك للمعاملة
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
