<?php

namespace App\Domains\Admin\Controllers;

use App\Domains\UserManagement\Actions\GenerateActivationToken\GenerateActivationTokenCommand;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UserResetPasswordController extends CommonController
{
    public function __invoke(int $id, Request $request): JsonResponse
    {
        $user = $this->adminUsers->findById($id);

        if (!$user->email) {
            return response()->json([
                'status' => 'error',
                'message' => 'Benutzer*in hat keine E-Mail-Adresse hinterlegt.',
            ]);
        }

        $command = new GenerateActivationTokenCommand($user);
        $command->execute();

        return response()->json([
            'status' => 'success',
            'message' => 'Passwort-Reset-Mail wurde gesendet.',
        ]);
    }
}
