<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MenuGroup extends Model
{
    protected $table = 'menu_groups';

    protected $fillable = [
        'tenant_id',
        'name',
        'description',
        'is_system',
        'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'is_system' => 'boolean',
    ];

    public function menus()
    {
        return $this->belongsToMany(
            MenuList::class,
            'menu_group_menus',
            'menu_group_id',
            'menu_id'
        )->withPivot([
            'can_view',
            'can_create',
            'can_update',
            'can_delete',
            'can_approve',
            'can_export',
        ])->withTimestamps();
    }

    public function userMenuGroups()
    {
        return $this->hasMany(UserMenuGroup::class, 'menu_group_id');
    }

    public function tenant()
    {
        return $this->belongsTo(Tenant::class);
    }
}
