<?php

namespace App\Models;

use Spatie\Activitylog\LogOptions;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Header extends Model
{
    use HasFactory;
    use SoftDeletes;
    use LogsActivity;
    protected $dates = ['deleted_at'];
    protected $fillable = [
        'name',
        'link',
        'slug',
        'status',
        'position',
        'parent_id',
        
    ];

    /**
     * Get the parent header for the current header.
     */
    public function parent()
    {
        return $this->belongsTo(Header::class, 'parent_id');
    }

    /**
     * Get the child headers for the current header.
     */
    public function children()
{
    return $this->hasMany(Header::class, 'parent_id');
}

public function hasChildren()
{
    return $this->children()->where('status',1)->orderBy('position', 'asc')->count() > 0;
}
public function getActivitylogOptions(): LogOptions
{
    return LogOptions::defaults()
    ->logAll();
}
}
