<?php

namespace App\Domains\Admin\Actions\ToggleUserActive;

class ToggleUserActiveAction
{
    public function __construct(private ToggleUserActiveRequest $request)
    {
    }

    public function execute(): ToggleUserActiveResponse
    {
        $response = new ToggleUserActiveResponse();

        if ($this->request->currentUserId === $this->request->user->id) {
            $response->message = 'Du kannst dich nicht selbst deaktivieren.';
            return $response;
        }

        $this->request->user->update(['active' => !$this->request->user->active]);

        $status = $this->request->user->active ? 'aktiviert' : 'deaktiviert';

        $response->success = true;
        $response->message = 'Benutzer*in wurde ' . $status . '.';
        $response->active = $this->request->user->active;

        return $response;
    }
}
