<?php
declare(strict_types=1);

namespace Autogedal\EanTools\Model\Spreadsheet;

class RowReaderResolver
{
    public function __construct(
        private readonly Format $format,
        private readonly CsvRowReader $csvRowReader,
        private readonly XlsxRowReader $xlsxRowReader
    ) {
    }

    public function forFile(string $path, ?string $originalName = null): RowReaderInterface
    {
        return $this->format->fromFileName($originalName ?? $path) === Format::XLSX
            ? $this->xlsxRowReader
            : $this->csvRowReader;
    }
}
