<?php

namespace App\Transformer\AIGeneration;

use Illuminate\Support\Facades\DB;

class AIGenerationTransformer
{
    // 剧本列表
    public function newBuildTaskList($data): array
    {
        return [
            'meta'      => getMeta($data),
            // 'header'    => $data['header'],
            'list'      => $this->newEachTaskList($data),
        ];
    }

    private function newEachTaskList($list): array
    {
        $result = [];
        if (empty($list)) return $result;

        foreach ($list as $item) {
            $status = getProp($item, 'status');
            $status_arr =[
                'pending' => '待生成',
                'processing' => '生成中',
                'success' => '生成成功',
                'failed' => '生成失败',
            ];

            $result[] = [
                'task_id'               => getProp($item, 'id'),
                'prompt'                => getProp($item, 'prompt'),
                'seed'                  => getProp($item, 'seed'),
                'video_resolution'      => getProp($item, 'video_resolution'),
                'video_duration'        => getProp($item, 'frames') ? round((getProp($item, 'frames') - 1) / 24) : 0,
                'result_url'            => getProp($item, 'result_url'),
                'last_frame_url'        => getProp($item, 'last_frame_url'),
                'api_type'              => getProp($item, 'api_type'),
                'status'                => $status,
                'status_info'           => isset($status_arr[$status]) ? $status_arr[$status] : '',
                'created_at'            => transDate(getProp($item, 'created_at')),
                'updated_at'            => transDate(getProp($item, 'updated_at')),
                'extra_params'          => getProp($item, 'extra_params'),
            ];
        }

        return $result;
    }

    
}
