<?php

namespace App\Console\Commands;

use App\Jobs\DownloadImageJob;
use App\Jobs\ReadDiscordMessageJob;
use App\Models\PromptTask;
use App\Service\TaskService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;

class TestsCommand extends Command
{
    protected $signature = 'tests';

    protected $description = '测试脚本';

    public function handle()
    {
//        $this->apiSubmit();

//        $this->readDiscordMessage();

        $this->downloadImage();
    }

    public function downloadImage()
    {
        $prompt = PromptTask::find(28);
        $downloadData = [
            'url' => $prompt->cut_img,
            'name' => Str::uuid()->toString(),
            'index' => 1,
            'prompt_id' => $prompt->id,
        ];
        dispatch(new DownloadImageJob($downloadData));
    }


    /**
     * 读取消息
     */
    public function readDiscordMessage()
    {
        $str = '{
  "message_id": 1096000262763708500,
  "message_content": "**illustration, futurism,NFT art, Fluorescent color, Laser color, A cute girlwho looks up and smiles, combinationof 2d and 3d, solid color background,cel shading,Tindal effect, Non- photorealistic rendering,Transparency,color Slant, animation, blender, geometry art, acrylic painting --q 2** - <@1075605512000905297> (fast)",
  "channel_id": 1090583268467945500,
  "author_id": 936929561302675500,
  "author_name": "Midjourney Bot",
  "author_discriminator": "9282",
  "guild_id": 1090583267612299300,
  "guild_name": "测试服务器",
  "attachment_url": "https://yunyi-tiktok.oss-cn-shenzhen.aliyuncs.com/files/download/admin/e4bfe50989519b8537f4741e0edf174e.png",
  "attachment_filename": "suifeng_illustration_futurismNFT_art_Fluorescent_color_Laser_co_994d7b33-9cad-4b0d-9e71-b401e576009e.png"
}';
        $data = json_decode($str, true);
       dispatch(new ReadDiscordMessageJob($data));
    }

    /**
     * 提交任务
     */
    public function apiSubmit()
    {
        $userId = 1;
        $data = [
            'prompt' => 'illustration, futurism,NFT art, Fluorescent color, Laser color, A cute girlwho looks up and smiles, combinationof 2d and 3d, solid color background,cel shading,Tindal effect, Non- photorealistic rendering,Transparency,color Slant, animation, blender, geometry art, acrylic painting --q 2',
            'prompt_img' => [
                "http://baidu.com",
            ],
            "prompt_num" => 5,
            "type" => 2,
        ];
        app(TaskService::class)->apiSubmit($userId, $data);
    }
}
