<?php

/**
 * PHP-IR class declaration with the currently supported static method subset.
 */
final class PhpIrClass
{
    private int $startLine;
    private int $endLine;
    private array $comments;
    private string $name;
    private array $methods;

    /**
     * Create a PHP-IR class declaration.
     */
    public function __construct(int $startLine, int $endLine, array $comments, string $name, array $methods)
    {
        $this->startLine = $startLine;
        $this->endLine = $endLine;
        $this->comments = $comments;
        $this->name = $name;
        $this->methods = $methods;
    }

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