<?php

namespace App\Http\Controllers\Api\User;

use App\Http\Controllers\Controller;
use App\Service\TaskService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class TaskController extends Controller
{

    /**
     * 提交任务
     *
     * @param Request $request
     * @return mixed
     */
    public function SubmitTask(Request $request)
    {
        $data = $request->input();
        $user = $request->user();
        $result = app(TaskService::class)->submit($user->id, $data);
        return $this->success('success', $result);
    }

    /**
     * api 提交任务
     *
     * @param Request $request
     * @return mixed
     */
    public function apiSubmit(Request $request)
    {
        $data = $request->input();
        $user = $request->user();
        $result = app(TaskService::class)->apiSubmit($user->id, $data);
        return $this->success('success', $result);
    }

    /**
     * stable 提交任务
     */
    public function stableSubmit(Request $request)
    {
        $data = $request->input();
        $user = $request->user();
        $result = app(TaskService::class)->stableSubmit($user->id, $data);
        return $this->success('success', $result);
    }

    /**
     * stable 获取任务
     *
     * @param Request $request
     * @return mixed
     */

    public function stableTask(Request $request)
    {
        $data = $request->input();
        $result = app(TaskService::class)->getStableTask($data);
        return $this->success('success', $result);
    }

    /**
     * stable任务回调
     */
    public function stableCallback(Request $request)
    {
        $data = $request->input();
        $result = app(TaskService::class)->stableCallback($data);
        return $this->success('success', $result);
    }

    /**
     * python-gpt任务回调
     */
    public function gpt_callback(Request $request)
    {
        $data = $request->input();
        $res = app(TaskService::class)->gpt_callback($data);
        return $this->success('success', $res);

    }

    /**
     * python - 指令完成-回调
     */
    public function prompt_callback(Request $request)
    {
        $data = $request->input();
        $res = app(TaskService::class)->prompt_callback($data);
        return $this->success('success', $res);
    }

    /**
     * python - 图片下载完成-回调
     */
    public function image_callback(Request $request)
    {
        $data = $request->input();
        $res = app(TaskService::class)->img_download_callback($data);
        return $this->success('success', $res);
    }

    /**
     * 轮询任务状态
     */
    public function task_callback(Request $request)
    {
        $data = $request->input();
        $user = $request->user();
        $res = app(TaskService::class)->task_callback($user->id, $data);
        return $this->success('success', $res);
    }

    /**
     * 创建切割图片任务
     */
    public function split_img(Request $request)
    {
        $data = $request->input();
        $user = $request->user();
        $res = app(TaskService::class)->create_split_img_task($user->id, $data);
        return $this->success('success', $res);
    }

    /**
     * 图片切割回调
     */
    public function split_callback(Request $request)
    {
        $data = $request->input();
        $res = app(TaskService::class)->split_callback($data);
        return $this->success('success', $res);
    }

    /**
     * 图片切割结果
     *
     * @param Request $request
     * @return mixed
     */
    public function split_img_result(Request $request)
    {
        $data = $request->input();
        $res = app(TaskService::class)->IntervalSplitImg($data);
        return $this->success('success', $res);
    }
}
