<?php

declare(strict_types=1);

namespace App\Support\Diff;

use InvalidArgumentException;

final readonly class DiffPresentation
{
    /**
     * @param  array<int, DiffRow>  $rows
     */
    public function __construct(
        public DiffSummary $summary,
        public array $rows,
    ) {
        foreach ($this->rows as $row) {
            if (! $row instanceof DiffRow) {
                throw new InvalidArgumentException('DiffPresentation rows must contain only DiffRow instances.');
            }
        }
    }

    public static function empty(?string $message = 'No diff data available.'): self
    {
        return new self(
            summary: DiffSummary::empty($message),
            rows: [],
        );
    }
}
