<?php

namespace App\Models\PaymentManagement;

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

class PaymentUsage extends Model{
    use HasFactory;

    protected $guarded = ["id"];

    //public $incrementing = false;
    //public $timestamps = false;
    protected $table = "payment_mgt__payment_usages";
    const MORPH_ID_COLUMN = "usageable_id";
    const MORPH_TYPE_COLUMN = "usageable_type";
    const MORPH_FUNCTION_NAME = "usageable";


    //SCOPES
    public function scopeUsed($query){
        return $query->where('deleted',false);
    }


    /**
     * @return MorphTo
     */
    public function usageable(){
        return $this->morphTo(__FUNCTION__,
            self::MORPH_TYPE_COLUMN,self::MORPH_ID_COLUMN);
    }

    public function payment(){
        return $this->belongsTo(Payment::class,"payment_id");
    }
}
