<?php

namespace App\Http\Controllers;

use App\Http\Requests\InfoBoxIndex;
use App\Libs\Services\InfoBoxFileService;

class InfoBoxFilesController extends Controller
{
    public function getInfoBox(InfoBoxIndex $request, InfoBoxFileService $infoBoxService)
    {
        $data = $request->validated();
        $infoBoxData = $infoBoxService->getInfoBox($data);
        if ($infoBoxData) {
            return $infoBoxData['infoBox'];
        }
        return response()->json([], 404);
    }

    public function createOrUpdate(InfoBoxIndex $request, InfoBoxFileService $infoBoxService)
    {
        $data = $request->validated();
        $infoBox = $infoBoxService->createOrUpdate($data);

        if (empty($infoBox)) {
            return response(['error' => 'Error'], 401);
        }

        return $infoBox;
    }

    public function deleteInfoBox(InfoBoxIndex $request, InfoBoxFileService $infoBoxService)
    {
        $data = $request->validated();
        $response = $infoBoxService->deleteInfoBox($data);
        return $response;
    }
}
