<?php

namespace App\Models\Admin;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class NavigationLink extends Model
{
    use HasFactory, HasTranslations;

    protected $fillable = [
        'parent_id',
        'navigation_menu_id',
        'page_id',
        'type',
        'title',
        'description',
        'url',
        'target',
        'class',
        'ordernum'
    ];

    public $translatable = [
        'title',
        'description',
        'url'
    ];

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

    public function children()
    {
        return $this->hasMany(NavigationLink::class, 'parent_id');
    }

    public function navigationMenu()
    {
        return $this->belongsTo(NavigationMenu::class);
    }

    public function page()
    {
        return $this->hasOne(Page::class, 'id');
    }
}
