<?php

namespace App\Models;

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

class LimitJournal extends Model
{
    use HasFactory;

    protected $fillable = [
        'journalable',
        'previous_balance',
        'total_credit',
        'total_debit',
        'type',
        'balance',
        'description',
    ];
    
    protected $hidden = [
        'created_at',
        'updated_at',
        'deleted_at',
        'created_by',
        'updated_by',
        'deleted_by',
    ];

    public function journalable()
    {
        return $this->morphTo();
    }
    
    public function setTotalCreditAttribute($value)
    {
        $this->attributes['total_credit'] = empty($value) ? 0 : $value;
    }

    public function setTotalDebitAttribute($value)
    {
        $this->attributes['total_debit'] =  empty($value) ? 0 : $value;
    }

}
