<?php

namespace App\Http\Controllers\Api;

use App\Model\MediaModel;
use App\Model\QiniuModel;
use App\Tool\SrsHookValidate;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use Qiniu\Auth;

class MediaController extends Controller
{

    /**
     * 获取媒资ID
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ControllerException
     */
    public function media_list(Request $request){

        $result = handler_drive(function () use ($request){

            SrsHookValidate::srsHookCallback($request,[
                'params'    => 'required'
            ]);

            return MediaModel::getMediaList($request);

        });

        return success($result);
    }

    /**
     * 获取媒资播放地址
     * @param Request $request
     * @param $media_id
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ControllerException
     */
    public function play_url(Request $request,$media_id){

        $result = handler_drive(function () use ($request,$media_id){
            return MediaModel::playUrl($media_id);
        });

        return success($result);

    }



    /**
     * 获取媒资列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ControllerException
     */
    public function mediaListOnce(Request $request){

        $res = handler_drive(function () use($request){

            SrsHookValidate::srsHookCallback($request,[
                'page'          => 'integer',
                'sort'          => '',
                'page_size'     => 'integer',
                'start_time'    => 'date',
                'end_time'      => 'date',
            ]);

            return MediaModel::mediaList($request);

        });
        return success($res);
    }


    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ControllerException
     */
    public function handleMediaUrl(Request $request){

        $res = handler_drive(function () use($request){
            SrsHookValidate::srsHookCallback($request,[
                'media_name'    => '',
                'username'      => '',
                'page'          => 'integer',
                'media_id'      => '',
                'description'   => '',
                'sort'          => '',
                'page_size'     => 'integer',
            ]);
            return MediaModel::handleMediaUrl($request);
        });
        return success($res);
    }










}
