<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Payment extends Model
{
    protected $fillable = [
        'client_id',
        'amount',
        'payment_mode',
        'instrument_owner',
        'instrument_number',
        'date_entree',
        'date_activation',
        'status',
        'creation_date',
    ];

    protected $casts = [
        'amount' => 'decimal:2',
        'date_entree' => 'date',
        'date_activation' => 'date',
        'creation_date' => 'date',
    ];

    public function client()
    {
        return $this->belongsTo(Client::class);
    }

    // Scope to filter cheque and trait payments
    public function scopeChequeOrTrait($query)
    {
        return $query->whereIn('payment_mode', ['cheque', 'trait']);
    }
}
