<?php

namespace App\Http\Controllers;

use App\Http\Requests\TemporaryFileUploadRequest;
use App\Services\TemporaryFileService;
use Illuminate\Http\Request;

class TemporaryFileController extends Controller
{

    public function __construct(private TemporaryFileService $services) {}

    public function upload(TemporaryFileUploadRequest $request){
        $file = $request->file('file');
        if( !$file || !$file->isValid()){
            response()->json( ['path' => null], 400);
        }

        $path = $this->services->uploadFile( $file );
        if( !$path ){
            response()->json( ['path' => null], 500);
        }

        return response()->json(['path' => $path]);
    }
}
