<?php

namespace App\Support;

use App\Models\AgentNode;

/** 列表/详情中嵌入的代理节点摘要字段。 */
final class AgentNodeApiPresenter
{
    /**
     * @return array{
     *   agent_node_id: ?int,
     *   agent_code: ?string,
     *   agent_name: ?string
     * }
     */
    public static function embed(?AgentNode $node): array
    {
        if (! $node instanceof AgentNode) {
            return [
                'agent_node_id' => null,
                'agent_code' => null,
                'agent_name' => null,
            ];
        }

        return [
            'agent_node_id' => (int) $node->id,
            'agent_code' => (string) $node->code,
            'agent_name' => (string) $node->name,
        ];
    }
}
