<?php

namespace App\Models\SettingManagement;

use App\Models\Traits\Bootables\Auditable;
use Axn\EloquentAuthorable\AuthorableTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class StatusChange extends Model{
    use HasFactory,Auditable,AuthorableTrait;


//    public $authorable = [
//        'updated_by_column_name' => false,
//        'set_author_when_creating' => true,
//        'set_author_when_updating' => false,
//    ];

    protected $guarded = ['id'];

    protected $table = "setting_mgt__statuses_changes";
    public $timestamps = false;
    const MORPH_ID_COLUMN = "changeable_id";
    const MORPH_TYPE_COLUMN = "changeable_type";
    const MORPH_FUNCTION_NAME = "changeable";

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

    /**
     * @return BelongsTo
     */
    public function status(){

      //  $related = get_class($this->changeable->status);
//        dd($this);
       // $related = $this->changeable->getStatusClass();
        return $this->belongsTo($this->changeable->getStatusClass(),"status_code");
//        return null;

    }
}
