<?php

namespace app\controller\jiandao;

use app\extra\basic\Base;
use app\extra\service\star\TaskVideoService;
use app\extra\tools\XcJob;
use DI\Attribute\Inject;
use LinFly\Annotation\Route\Controller;
use LinFly\Annotation\Route\Route;
use support\Request;
use support\Response;


#[Controller(prefix: "/jd/xt")]
class JDXingtu extends Base
{

    #[Inject]
    protected TaskVideoService $service;

    protected array $status = [
        3 => "已完成",
        31 => "平台审核中",
        32 => "审核未通过",
        33 => "审核未通过",
        70 => "服务商审核中",
        71 => "审核未通过",
        72 => "预热中",
        73 => "审核超时",
        74 => "客户审核中",
        75 => "审核未通过",
        76 => "审核超时",
        80 => "持续计费中",
        81 => "结果公示中",
        82 => "计费暂停",
    ];

    /**
     * 星川任务素材信息
     * @param Request $request
     * @return Response
     */
    #[Route(path: "video",methods: "get")]
    public function getXtVideo(Request $request): Response
    {
        try {
            $param = $this->_valid([
                "job.require"   => trans("empty.require"),
                "page.default"  => 1,
                "size.default"  => 10,
            ],$request->method());
            if (!is_array($param)) return error($param);
            $param['pageSize'] = $param['size'];
            $list = $this->service->getList($param);
            return successTrans("success.data",pageFormat($list),200);
        } catch (\Throwable $throwable) {
            return error($throwable->getMessage());
        }
    }


    /**
     * 获取单个任务中指定达人的投稿视频-试试
     * @param Request $request
     * @return Response
     */
    #[Route(path: "user",methods: "get")]
    public function getXtUserVideo(Request $request): Response
    {
        try {
            $param = $this->_valid([
                "job.require"   => trans("empty.require"),
                "star.require"   => trans("empty.require"),
                "page.default"  => 1,
                "size.default"  => 10,
            ],$request->method());
            if (!is_array($param)) return error($param);
            [$state,$videoData] = (new XcJob)->token()->getAuthorVide2Task($param['job'],$param['star'],$param['page'],$param['size']);
            if (!$state) return error("获取数据失败");
            $data = [];
            foreach ($videoData['list'] as $key=>$sv)
            {
                [$vState,$videDetail] = (new XcJob)->token()->getVideoDetail($sv['base_info']['video_id']);
                $data[$key] = [
                    "job_id"        => $param['job'],
                    "author_id"     => (string) $sv['author_info']['author_id'],
                    "play_url"      => $vState ? $videDetail['play_url'] : '',
                    "cover"         => $vState ? $videDetail['cover'] : '',
                    "title"         => removeEmoji2($sv['base_info']['title']),
                    "duration"      => $sv['base_info']['duration'],
                    "item_id"       => (string) $sv['base_info']['item_id'],
                    "lego_mid"      => (string) $sv['ad_info']['lego_mid'],
                    "video_id"      => (string) $sv['base_info']['video_id'],
                    "item_status"   => $this->status[$sv['extra_info']['item_status']],
                    "time_agg_data_10006"   => $sv['item_real_time_agg_data']['10006']??0,
                    "time_agg_data_10010"   => $sv['item_real_time_agg_data']['10010']??0,
                    "time_agg_data_10014"   => $sv['item_real_time_agg_data']['10014']??0,
                    "time_agg_data_10035"   => $sv['item_real_time_agg_data']['10035']??0,
                    "time_agg_data_10036"   => $sv['item_real_time_agg_data']['10036']??0,
                    "time_agg_data_10057"   => $sv['item_real_time_agg_data']['10057']??0,
                    "time_agg_data_10056"   => $sv['item_real_time_agg_data']['10056']??0,
                    "time_agg_data_10058"   => $sv['item_real_time_agg_data']['10058']??0,
                    "time_agg_data_10059"   => $sv['item_real_time_agg_data']['10059']??0,
                    "time_agg_data_10060"   => $sv['item_real_time_agg_data']['10060']??0,
                    "time_agg_data_10061"   => $sv['item_real_time_agg_data']['10061']??0,
                    "indicator_agg_data_20021"   => $sv['bill_indicator_agg_data']['20021']??0,
                    "indicator_agg_data_20022"   => $sv['bill_indicator_agg_data']['20022']??0,
                    "indicator_agg_data_20020"   => $sv['bill_indicator_agg_data']['20020']??0,
                    "indicator_agg_data_20019"   => $sv['bill_indicator_agg_data']['20019']??0,
                    "indicator_agg_data_20016"   => $sv['bill_indicator_agg_data']['20016']??0,
                    "indicator_agg_data_20015"   => $sv['bill_indicator_agg_data']['20015']??0,
                    "indicator_agg_data_20011"   => $sv['bill_indicator_agg_data']['20011']??0,
                ];
            }
            return successTrans("success.data",[
                "total"     => $videoData['total'],
                "page"      => $videoData['page'],
                "pageSize"  => intval($param['size']),
                "rows"      => $data
            ],200);
        } catch (\Throwable $throwable) {
            return error($throwable->getMessage());
        }
    }

}