<?php
namespace App\Domains\Artisan\Http\Controllers;

use App\Core\Controller;
use Illuminate\Http\Request;
use App\Domains\Artisan\Services\ArtisanService;

class ArtisanController extends Controller
{
    protected $request;
    protected $artisanService;

    /**
     * 构造函数，自动注入.
     */
    public function __construct(Request $request, ArtisanService $artisanService)
    {
        $this->request = $request;
        $this->artisanService = $artisanService;
    }

    /**
     * 列表.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $conditions = $this->request->all();

        $res = $this->artisanService->index($conditions);

        return res($res, '命令记录', 201);
    }


    /**
     * 执行.
     *
     * @return \Illuminate\Http\Response
     */
    public function call()
    {
        begin_time_consuming();

        $command = $this->request->get('command');
        $parameters = $this->request->get('parameters', []);

        $this->artisanService->call($command, $parameters);

        return res(true, '执行成功');
    }
}
