<?php

namespace LaraBB\Group\Actions\Admin;

use LaraBB\Group\Tasks\StoreTask;
use LaraBB\Group\UI\Web\Requests\Store;

/**
 * Class StoreAction
 * @package LaraBB\Group\Actions\Admin
 */
class StoreAction
{
    /**
     * @var StoreTask
     */
    private StoreTask $storeGroupTask;

    /**
     * StoreAction constructor.
     * @param StoreTask $storeGroupTask
     */
    public function __construct(StoreTask $storeGroupTask)
    {
        $this->storeGroupTask = $storeGroupTask;
    }

    /**
     * @param Store $request
     * @return bool
     */
    public function run(Store $request): bool
    {
        return $this->storeGroupTask->run($this->prepareGroupData($request));
    }

    /**
     * @param Store $request
     * @return array
     */
    private function prepareGroupData(Store $request): array
    {
        return [
            'created_uuid' => $request->user()->uuid,
            'updated_uuid' => $request->user()->uuid,
            'group'        => $request->post('group'),
            'color'        => $request->post('color'),
            'priority'     => $request->post('priority')
        ];
    }
}
