<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Response\ResponseJson;
use App\Models\DmaProcess;
use App\Models\DmaProcessLog;
use App\Models\Order;
use App\Models\OrderVideo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class VideoController extends Controller
{
    use ResponseJson;

    public function addOrderVideo(Request $request){
        try {
            $video_url = $request->input('video_url');
            $desc = $request->input('desc');
            $order_id = $request->input('order_id');
            $step = $request->input("step");

            $order = Order::where('id',$order_id)->orderByDesc("id")->first();

            OrderVideo::create(['order_id'=>$order->id,'video_title'=>$order->name,'video_url'=>$video_url,'desc'=>$desc,"step"=>$step]);
            $step_name = "send_first_order_video";
            $step_ch = "一";
            if($step == 2){
                $step_name = "send_second_order_video";
                $step_ch = "二";
            }elseif ($step == 3){
                $step_name = "send_third_order_video";
                $step_ch = "三";
            }
            DmaProcessLog::addUserProcessLog($order->user_id??0,$order_id,1,$step_name,"进行第".$step_ch."视频通话",auth()->user()->id??0,4);
            return $this->success('ok');
        }catch (\Exception $e) {
            return $this->failure($e);
        }
    }

    public function getOrderVideoList(Request $request){
        try {
            $order_id = $request->get('order_id');
            $list = OrderVideo::where('order_id',$order_id)->paginate();
            return $this->success('ok',$list);
        }catch (\Exception $e) {
            return $this->failure($e);
        }
    }

    public function deleteOrderVideo($id){
        OrderVideo::where('id',$id)->delete();
        return $this->success('ok');
    }
}