<?php

namespace App\Domains\Admin\Controllers;

use App\Domains\Admin\Actions\ToggleUserActive\ToggleUserActiveAction;
use App\Domains\Admin\Actions\ToggleUserActive\ToggleUserActiveRequest;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

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

        $action = new ToggleUserActiveAction(new ToggleUserActiveRequest(
            user: $user,
            currentUserId: auth()->id(),
        ));

        $response = $action->execute();

        return response()->json([
            'status' => $response->success ? 'success' : 'error',
            'message' => $response->message,
            'active' => $response->active,
        ]);
    }
}
