<?php

namespace App\Models\Permissions;

use App\Models\Commons\IdeHelperRole;
use App\Models\Members\UserRole;
use App\Models\Tenants\Tenant;
use Illuminate\Database\Eloquent\Model;

/**
 * @mixin IdeHelperRole
 */
class Role extends Model
{
    protected $fillable = [
        'tenant_id', 'name', 'description',
    ];

    public function menuPermissions()
    {
        return $this->hasMany(RoleMenuPermission::class, 'role_id');
    }

    public function permissions()
    {
        return $this->belongsToMany(
            Permission::class,
            'role_has_permissions',
            'role_id',
            'permission_id'
        );
    }

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

    public function userRoles()
    {
        return $this->hasMany(UserRole::class);
    }
}
