<?php

namespace App\Http\Controllers\Admin\Config;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Config;
use Artisan;

class OptimizeController extends Controller
{
    private Config $configModel;

    public function __construct(Config $config)
    {
        $this->configModel = $config;
    }

    /**
     * 복구 / 최적화
     * @method GET
     * @see /admin/config/optimize
     */
    public function index()
    {
        return view('admin.config.optimize.index', []);
    }

    /**
     * 1: Clear Application Cache
     * 2: Clear Route Cache
     * 3: Clear Configuration Cache
     * 4: Clear Compiled Views Cache
     * @method GET
     * @see /admin/config/optimize
     */
    public function clear(Request $request)
    {
        $cmd = $request->segment(5);
        switch($cmd) {
            case 'appCache' :
                $cmd = 'cache:clear';
                break;
            case 'routeCache' :
                $cmd = 'route:clear';
                break;
            case 'configCache' :
                $cmd = 'config:clear';
                break;
            case 'viewCache' :
                $cmd = 'view:clear';
                break;
        }

        Artisan::call($cmd);
        $message = Artisan::output();
        return redirect()->route('admin.config.optimize')->with('message', $message);
    }
}
