<?php
declare(strict_types=1);

namespace Autogedal\EanTools\Model\Spreadsheet;

class RowWriterFactory
{
    public function __construct(
        private readonly Format $format,
        private readonly CsvRowWriterFactory $csvRowWriterFactory,
        private readonly XlsxRowWriterFactory $xlsxRowWriterFactory
    ) {
    }

    public function create(string $absolutePath, string $format, array $header): RowWriterInterface
    {
        $arguments = ['absolutePath' => $absolutePath, 'header' => $header];

        return $this->format->resolve($format) === Format::XLSX
            ? $this->xlsxRowWriterFactory->create($arguments)
            : $this->csvRowWriterFactory->create($arguments);
    }
}
