<?php
namespace App\Contracts;

class ContractResult
{
    public array $sections = [];

    public function addSection(string $name, string $content): void
    {
        // Si ya existe el nombre, agregamos el contenido al array
        if (!isset($this->sections[$name])) {
            $this->sections[$name] = [];
        }

        $this->sections[$name][] = $content;
    }

    public function toHtml(): string
    {
        $html = '';
        foreach ($this->sections as $name => $contents) {
            foreach ($contents as $content) {
                $html .= $content;
            }
        }
        return $html;
    }

    public function toArray(): array
    {
        return $this->sections;
    }
}