<?php

namespace App\Models;

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

class Level extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var string[]
     */
    protected $fillable = [
        'title',
        'code',
        'parent_level',
        'stage_id',
    ];

    public static function getLevelsStagesIds($levels)
    {
       $levelsModels = Level::select('stages.id')->distinct()
            ->join('stages', 'stages.id', '=', 'levels.stage_id')
            ->whereIn('levels.id', $levels)->get();
            $levels =[];
            foreach ($levelsModels as  $value) {
                $levels[] = $value['id'];
            }
            return $levels;
    }
}
