<?php

declare(strict_types=1);

namespace App\Framework\Admin\ValueObjects;

use App\Framework\Http\Method;

/**
 * Admin Form Configuration
 *
 * Configuration for creating admin forms
 */
final readonly class AdminFormConfig
{
    /**
     * @param array<string, array{type: string, label: string, required?: bool, options?: array, placeholder?: string, help?: string}> $fields
     * @param array<string, mixed> $data
     */
    public function __construct(
        public string $resource,
        public string $action,
        public Method $method,
        public array $fields,
        public array $data = [],
    ) {
    }

    public static function create(
        string $resource,
        string $action,
        Method $method,
        array $fields
    ): self {
        return new self(
            resource: $resource,
            action: $action,
            method: $method,
            fields: $fields
        );
    }

    public function withData(array $data): self
    {
        return new self(
            resource: $this->resource,
            action: $this->action,
            method: $this->method,
            fields: $this->fields,
            data: [...$this->data, ...$data]
        );
    }
}
