<?php

declare(strict_types=1);

namespace Apexl\UserTabulator\Controllers;

use apexl\Io\interfaces\OutputManagerInterface;
use apexl\Io\services\Output;
use Apexl\UserLayout\Controllers\AbstractSaveLayoutController;
use Apexl\UserLayout\Requests\SaveLayoutRequest;
use Apexl\UserTabulator\Dto\TabulatorLayoutDto;
use Apexl\UserTabulator\Services\TabulatorUserLayoutKeyService;

final readonly class SaveTabulatorLayoutController extends AbstractSaveLayoutController
{
    public function __construct(
        OutputManagerInterface $output,
        private TabulatorUserLayoutKeyService $keyService
    ) {
        parent::__construct($output);
    }

    protected function dto(SaveLayoutRequest $request): TabulatorLayoutDto
    {
        return TabulatorLayoutDto::fromColumnsArray($request->layout());
    }

    protected function key(string $viewId): string
    {
        return $this->keyService->key($viewId);
    }
}
