# 视频上传
module AliyunVod::Service::VideoUpload
  # 获取视频上传地址和凭证
  def create_upload_video(title, filename, **opts)
    params = {
      Action: 'CreateUploadVideo',
      Title: title,
      FileName: filename
    }.merge(base_params)

    # TODO： 获取视频的同时，可以指定转码组，在这里指定
    # 参数TemplateGroupId： 转码组的id.
    # 分类
    cate_id = AliyunVod.cate_id
    params[:CateId] = cate_id if cate_id.present?

    params = opts.merge(params)

    result = request(:post, params)

    raise AliyunVod::Error, '获取上传凭证失败' if result['UploadAddress'].blank?

    result
  end

  # 刷新视频上传凭证
  def refresh_upload_video(video_id)
    params = {
      Action: 'RefreshUploadVideo',
      VideoId: video_id
    }.merge(base_params)

    result = request(:post, params)

    raise AliyunVod::Error, '刷新上传凭证失败' if result['UploadAddress'].blank?

    result
  end
end