<?php

namespace Src\Modules\JsonObjects\Laravel\Controllers;

use Illuminate\Http\Request;
use App\Providers\AppServiceProvider;
use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory;
use Src\Modules\JsonObjects\Application\FilesBrowser;

class FilesBrowserController {

    protected FilesBrowser $filesBrowser;

    public function __construct()
    {
        /** @var IModuleFactory $factory */
        $factory = app()->get(AppServiceProvider::ADMIN_MODULES)->getNewsModule();
        $this->filesBrowser = $factory->getApplicationFactory()->getFilesBrowser();
    }

    public function upload(Request $request)
    {
        $data = $request->all();
        return $this->filesBrowser->upload($data);
    }

    public function create(Request $request)
    {
        $data = $request->all();
        return $this->filesBrowser->create($data);
    }

    public function move(Request $request)
    {

    }

    public function remove(Request $request)
    {

    }

    public function items(Request $request)
    {
        $data = $request->all();
        return $this->filesBrowser->items($data);
    }

    public function tree(Request $request)
    {
        return [];
    }

    public function folder(Request $request)
    {
        $data = $request->all();
        return $this->filesBrowser->folder($data);
    }

    public function ajax(Request $request)
    {
        $data = $request->all();
        $action = $data['action'];

        switch ($action) {
            case 'permissions':
                return $this->filesBrowser->getPermissions();
            case 'folderRemove':
                return $this->filesBrowser->folderRemove($data);
            case 'folderRename':
                return $this->filesBrowser->folderRename($data);
            case 'fileRemove':
                return $this->filesBrowser->fileRemove($data);
        }
    }

}