<?php
declare(strict_types=1);

namespace PpPhp\Core\Designer\Property;

final class DesignerPropertySection
{
    public function __construct(
        private readonly string $sectionId,
        private readonly string $label,
        private readonly array $fields = [],
        private readonly int $order = 100
    ) {}

    public static function create(string $sectionId, string $label, array $fields = [], int $order = 100): self
    {
        return new self($sectionId, $label, $fields, $order);
    }

    public function sectionId(): string { return $this->sectionId; }
    public function order(): int { return $this->order; }
    public function fields(): array { return $this->fields; }

    public function withField(array $field): self
    {
        return new self($this->sectionId, $this->label, array_merge($this->fields, [$field]), $this->order);
    }

    public function toArray(): array
    {
        return [
            'sectionId' => $this->sectionId,
            'label' => $this->label,
            'fields' => $this->fields,
            'order' => $this->order,
        ];
    }
}
