<?php

namespace App\Models;

use App\Scopes\OrganisationScope;
use Auth;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class JobGrade extends Model
{
    //
    protected $guarded = [];

    protected static function booted()
    {
        static::addGlobalScope(new OrganisationScope());
        // Automatically set the organisation_id before creating the model
        static::creating(function ($model) {
            if (Auth::check()) {
                $model->organisation_id = Auth::user()->organisation_id;
            }
        });
    }




    /**
     * Get the designations that owns the JobGrade
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function designations(): HasMany
    {
        return $this->hasMany(Designation::class);
    }
}
