<?php


namespace App\Models\SettingManagement\Traits;


use App\Models\SettingManagement\Status;
use App\Models\Traits\HasStatusChanges;
use Illuminate\Database\Eloquent\Model;

trait Statuable{

    use HasStatusAttributes,HasStatusChanges;


    public static function bootStatuable(){
        static::created(function (Model $model) {
            $model->statuffy("created");
        });

        static::updated(function (Model $model) {
            $model->statuffy("updated");
        });
    }

    public function getStatusClass(){
        return Status::class;
    }

    public function status(){
        $statusClass = (new static)->getStatusClass();
        return $this->belongsTo($statusClass,"status_code");
    }
}
