<?php

/**
 * PHP-IR numeric multiplication expression for PHP binary *.
 */
final class PhpIrMultiply
{
    private int $startLine;
    private int $endLine;
    private array $comments;
    private object $left;
    private object $right;

    /** Create a numeric multiplication expression. */
    public function __construct(int $startLine, int $endLine, array $comments, object $left, object $right)
    {
        $this->startLine = $startLine;
        $this->endLine = $endLine;
        $this->comments = $comments;
        $this->left = $left;
        $this->right = $right;
    }

    /** Convert to a plain array for debugging/export. */
    public function toArray(): array
    {
        return [
            'kind' => 'Multiply',
            'startLine' => $this->startLine,
            'endLine' => $this->endLine,
            'comments' => array_map(static fn (PhpIrComment $comment): array => $comment->toArray(), $this->comments),
            'left' => method_exists($this->left, 'toArray') ? $this->left->toArray() : ['kind' => get_debug_type($this->left)],
            'right' => method_exists($this->right, 'toArray') ? $this->right->toArray() : ['kind' => get_debug_type($this->right)],
        ];
    }
}
