<?php

namespace Lucent\Record;

use Lucent\Channel\ChannelService;
use Lucent\Schema\FieldInterface;

class InputFormatter
{

    public function __construct(
        public ChannelService $channelService,
    )
    {
    }

    public function fill(string $schemaName, RecordData $input): RecordData
    {
        $schema = $this->channelService->getSchema($schemaName)->get();
        $data = $schema->fields->reduce(fn(array $carry, FieldInterface $field) => $field->format($input->toArray(), $carry), []);
        return new RecordData($data);
    }


}
