<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class RiskBasedInterestRate extends Model
{

    use SoftDeletes;

    protected $table = 'risk_based_interest_rate_changes';

    protected $fillable = ['application_id', 'user_id', 'new_interest_rate', 'is_excluding_pf', 'gross_roi', 'deleted_by'];


    public static function getInterestRate($id, $interest_rate){
        $riskBasedInterestRate = RiskBasedInterestRate::where('application_id', $id)->orderBy('created_at', 'desc')->first(['id', 'new_interest_rate']);
        return $riskBasedInterestRate->new_interest_rate ?? $interest_rate;
    }
}
