<?php

namespace App\Models;

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

class WithdrawHistory extends Model
{
    use HasFactory;

    protected $table = 'withdraw_history';

    protected $primaryKey = 'id';

    public $timestamps = true; 

    protected $fillable = [
        'user_id',
        'status',
        'method',
        'method_id',
        'method_name',
        'currency',
        'currency_id',
        'wallet',
        'ip_address',
        'amount',
        'amountusd',
        'fee',
        'trans_id',
    ];

    protected $casts = [
        'amount' => 'decimal:8',
        'amountusd' => 'decimal:6',
        'fee' => 'decimal:6',
    ];

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

    public function method()
    {
        return $this->belongsTo(WithdrawMethod::class, 'method_id');
    }

    public function scopeByUser($query, $userId)
    {
        return $query->where('user_id', $userId);
    }

    public function scopeByMethod($query, $methodId)
    {
        return $query->where('method_id', $methodId);
    }
}
