<?php

namespace LaraBB\User\Actions\Admin;

use JetBrains\PhpStorm\ArrayShape;
use LaraBB\Group\Tasks\FindTask as FindGroupTask;
use LaraBB\User\Tasks\FindTask as FindUserTask;
use LaraBB\User\UI\Web\Requests\Edit;

/**
 * Class EditAction
 * @package LaraBB\User\Actions\Admin
 */
class EditAction
{
    /**
     * EditAction constructor.
     * @param FindUserTask $findUserTask
     * @param FindGroupTask $findGroupTask
     */
    public function __construct(
        private readonly FindUserTask $findUserTask,
        private readonly FindGroupTask $findGroupTask
    ) {
    }

    /**
     * @param Edit $request
     * @return array
     */
    #[ArrayShape([
        'user'      => "\LaraBB\User\Models\User",
        'groups'    => "\Illuminate\Database\Eloquent\Collection|mixed|null",
        'active'    => "string",
        'subactive' => "string"
    ])]
    public function run(Edit $request): array
    {
        return [
            'user'      => $this->findUserTask->byUuid($request->route('uuid'), ['groups']),
            'groups'    => $this->findGroupTask->all(),
            'active'    => 'users',
            'subactive' => 'user'
        ];
    }
}
