<?php

namespace App\Transformer\DeepSeek;

use Illuminate\Support\Facades\DB;

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

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

        foreach ($list as $item) {
            $script_id = getProp($item, 'id');

            // 获取分集信息
            $episodes = DB::table('mp_script_episodes')->where('script_id', $script_id)->orderBy('sequence')->select('title', 'episode_number', 'content', 'segment_number', 'segment_content')->get()->map(function ($value) {
                return (array)$value;
            })->toArray();
            $result[] = [
                'user_id'               => getProp($item, 'user_id'),
                'script_id'             => $script_id,
                'script_name'           => getProp($item, 'script_name'),
                'status'                => getProp($item, 'status'),
                'created_at'            => transDate(getProp($item, 'created_at')),
                'updated_at'            => transDate(getProp($item, 'updated_at')),
                'episodes'              => $episodes,
            ];
        }

        return $result;
    }

    
}
