<?php

namespace App;

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

class EmiPayment extends Model
{

//    protected static function boot()
//    {
//        parent::boot();
//
//        static::created(function ($model) {
//            $backtrace = debug_backtrace();
//            sendToCloudWatch(['event' => 'emi_payment_creation_backtrace', 'application_id' => $model->application_id, 'created_at' => $model->created_at ,'backtrace' => $backtrace]);
//        });
//
//        /*static::updated(function ($model) {
//
//        });
//
//        static::deleted(function ($model) {
//
//        });*/
//    }

    protected $table = 'emi_payments';

    public function transaction()
    {
        return $this->hasMany('App\PaymentTransaction','emi_payment_id','id')->whereNull('is_deleted_at')->orderBy('emi_payment_id');
    }

    public function application(){

        return $this->hasOne('App\ConsumerApplication','id','application_id')->whereNull('is_deleted');
    }

    public function moratoriums(){
        return $this->hasMany('App\Moratorium','application_id','application_id')->where('status',1);
    }

    public function application_element(){
        $application_element = $this->hasOne('App\ConsumerApplicationElement','application_id','application_id');
        return $application_element;
    }
}
