import { defHttp } from '/@/utils/http/axios';
import {
  CameraModel,
  CameraQueryParam,
  CameraRecord,
  StreamingMediaDeleteParam,
  StreamingQueryParam,
  StreamingSubmitParam,
} from './model/cameraModel';
import { PaginationResult } from '/#/axios';

enum CameraManagerApi {
  CAMERA_POST_URL = '/video',
  CAMERA_GET_URL = '/video',
  CAMERA_DELETE_URL = '/video',
  CAMERA_GET_DETAIL_URL = '/video',
  STREAMING_GET_URL = '/video/platform',
  STREAMING_POST_URL = '/video/platform',
  STREAMING_DELETE_URL = '/video/platform',
  STREAMING_PLAY_GET_URL = '/video/url',
}

export const cameraPage = (params: CameraQueryParam) => {
  return defHttp.get<PaginationResult<CameraRecord>>({
    url: CameraManagerApi.CAMERA_GET_URL,
    params,
  });
};

/**
 * 删除视频
 * @param ids 删除的ids
 */
export const deleteCameraManage = (ids: string[]) => {
  return defHttp.delete({
    url: CameraManagerApi.CAMERA_DELETE_URL,
    data: {
      ids: ids,
    },
  });
};

// 创建或编辑视频
export const createOrEditCameraManage = (data) => {
  return defHttp.post<CameraModel>({
    url: CameraManagerApi.CAMERA_POST_URL,
    data,
  });
};

// 查询视频详情
export const getCameraManageDetail = (id: string) => {
  return defHttp.get({
    url: CameraManagerApi.CAMERA_GET_DETAIL_URL + `/${id}`,
  });
};

/**
 * @description 获取流媒体列表
 * @param params
 * @returns
 */
export const getStreamingMediaList = (params: StreamingQueryParam) => {
  return defHttp.get({
    url: CameraManagerApi.STREAMING_GET_URL,
    params,
  });
};

/**
 * @description 更新/新增流媒体记录
 * @param params
 * @returns
 */
export const createOrUpdateStreamingMediaRecord = (params: StreamingSubmitParam) => {
  return defHttp.post({
    url: CameraManagerApi.STREAMING_POST_URL,
    params,
  });
};

/**
 * @description 删除流媒体记录
 * @param params
 * @returns
 */
export const deleteStreamingMediaRecord = (params: StreamingMediaDeleteParam) => {
  return defHttp.delete({
    url: CameraManagerApi.STREAMING_POST_URL,
    params,
  });
};

/**
 * @description 获取流媒体播放地址
 * @param entityId
 * @returns
 */
export const getStreamingPlayUrl = (entityId: string) => {
  return defHttp.get({
    url: `${CameraManagerApi.STREAMING_PLAY_GET_URL}/${entityId}`,
  });
};
