<?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
{
    public function SubmitTask(Request $request)
    {
        $data = $request->input();
        $user = $request->user();
        $result = app(TaskService::class)->submit($user->id, $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);
    }

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