import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { UserVideoPlayForm, UserVideoPlayQuery, UserVideoPlayVO } from '@/api/system/video/types';

/**
 * 查询视频列表
 * @param query
 * @returns {*}
 */
export const listUserVideoInfo = (query?: UserVideoPlayQuery): AxiosPromise<UserVideoPlayVO[]> => {
  return request({
    url: '/resource/video/userVideoPlay/list',
    method: 'get',
    params: query
  });
};

/**
 * 根据视频ID获取详细信息
 * @param videoId
 */
export const getUserVideoInfo = (videoId: string | number) => {
  return request({
    url: '/resource/video/userVideoPlay/' + videoId,
    method: 'get'
  });
};

/**
 * 新增视频基本信息
 * @param data
 */
export const addVideoInfo = (data: UserVideoPlayForm): AxiosPromise<{ videoId: string }> => {
  return request({
    url: '/resource/video/userVideoPlay/add',
    method: 'post',
    data: data
  });
};

/**
 * 修改视频基本信息
 * @param data
 */
export const updateVideoInfo = (data: UserVideoPlayForm & { id?: string }) => {
  return request({
    url: '/resource/video/userVideoPlay/update',
    method: 'put',
    data: data
  });
};

/**
 * 视频文件上传
 * @param data
 */
export const videoUpload = (data: FormData) => {
  return request({
    url: '/resource/video/userVideoPlay/uploadFile',
    method: 'post',
    data: data
  });
};

/**
 * 根据id查询视频URL
 * @param data
 */
export const queryVideoUrl = (data?: UserVideoPlayVO) => {
  return request({
    url: '/resource/video/userVideoPlay/queryVideoUrl',
    method: 'post',
    data: data
  });
};

/**
 * 删除视频
 * @param ids
 */
export const deleteVideoInfo = (ids: string | number | Array<number | string>) => {
  return request({
    url: '/resource/video/userVideoPlay/' + ids,
    method: 'delete'
  });
};

/**
 * 根据功能路径查询URL
 * @param data
 */
export const queryVideoUrlByPath = (data: FormData) => {
  return request({
    url: '/video/userVideoPlay/queryVideoUrlByPath',
    method: 'post',
    data: data
  });
};

/**
 * 批量删除视频
 * @param ids
 */
export const batchDeleteVideo = (ids: Array<string | number>) => {
  return request({
    url: '/resource/video/userVideoPlay/batch/' + ids.join(','),
    method: 'delete'
  });
};

/**
 * 根据帮助代码查询视频
 * @param helpCode 帮助代码
 */
export const queryVideoByHelpCode = (helpCode: string): AxiosPromise<UserVideoPlayVO> => {
  return request({
    url: '/resource/video/userVideoPlay/queryByHelpCode/' + helpCode,
    method: 'get'
  });
};
