<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class NavigationItem extends Model
{
    protected $fillable = ['parent_id', 'label', 'url', 'open_in_new_tab', 'is_active', 'sort_order'];

    protected function casts(): array
    {
        return [
            'open_in_new_tab' => 'boolean',
            'is_active'       => 'boolean',
            'sort_order'      => 'integer',
            'parent_id'       => 'integer',
        ];
    }

    public function children(): HasMany
    {
        return $this->hasMany(NavigationItem::class, 'parent_id')->orderBy('sort_order');
    }

    public function parent(): BelongsTo
    {
        return $this->belongsTo(NavigationItem::class, 'parent_id');
    }
}
