<?php

namespace App\Modules\Customization\CustomFields\DTOs;

use Illuminate\Http\Request;

final readonly class CustomFieldsPayload
{
    /**
     * @param  array<string, mixed>  $values
     * @param  array<string, mixed>  $files
     */
    public function __construct(
        public array $values = [],
        public array $files = [],
    ) {}

    public static function fromRequest(Request $request): self
    {
        $rawFiles = $request->file('custom_fields');
        $files = is_array($rawFiles) ? $rawFiles : [];

        return new self(
            values: (array) $request->input('custom_fields', []),
            files: $files,
        );
    }
}
