<?php

namespace classes;

use modules\subusers\helpers\subusers_permission_node_key;

/**
 * Lightweight DTO that links a classic string permission to an optional
 * Subusers permission node key. Used by routes to declare permissions
 * that can be satisfied by either the main user permission system or
 * a subuser's granted permission node, depending on who is authenticated.
 */
class permission_node
{
    /**
     * The classic user permission string (e.g. "modules_motorapi_lookup")
     */
    public string $permission;

    /**
     * Optional subusers node key that mirrors this permission for subusers
     */
    public ?subusers_permission_node_key $subusers_node_key;

    public function __construct(string $permission, ?subusers_permission_node_key $subusers_node_key = null)
    {
        $this->permission = $permission;
        $this->subusers_node_key = $subusers_node_key;
    }

    public static function create(string $permission, ?subusers_permission_node_key $subusers_node_key = null): self
    {
        return new self($permission, $subusers_node_key);
    }
}
