<?php

/**
 * Vala-IR expression for a Zval array literal.
 */
final class ValaIrArrayLiteral
{
    private int $startLine;
    private int $endLine;
    private array $comments;
    private array $items;

    /**
     * Create the IR node.
     */
    public function __construct(int $startLine, int $endLine, array $comments, array $items)
    {
        $this->startLine = $startLine;
        $this->endLine = $endLine;
        $this->comments = $comments;
        $this->items = $items;
    }

    /**
     * Convert to a plain array for debugging/export.
     */
    public function toArray(): array
    {
        return [
            'kind' => 'ArrayLiteral',
            'startLine' => $this->startLine,
            'endLine' => $this->endLine,
            'comments' => array_map(static fn (ValaIrComment $comment): array => $comment->toArray(), $this->comments),
            'items' => array_map(
                static fn (ValaIrArrayItem $item): array => $item->toArray(),
                $this->items,
            ),
        ];
    }
}
