<?php

namespace App\Domains\Event\Controllers;

use App\Domains\Event\Actions\UnarchiveEvent\UnarchiveEventCommand;
use App\Domains\Event\Actions\UnarchiveEvent\UnarchiveEventRequest;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class EventUnarchiveController extends CommonController
{
    public function __invoke(int $eventId, Request $request): JsonResponse {
        $event = $this->events->getById($eventId);

        $unarchiveRequest = new UnarchiveEventRequest($event);
        $unarchiveCommand = new UnarchiveEventCommand($unarchiveRequest);
        $response = $unarchiveCommand->execute();

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