/*
 *    Copyright (c) 2018-2025, okayx All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the okaygis.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: okayx
 */

import request from '@/router/axios'
// 上传文件
export const uploadFileApi = (http, form, onUploadProgress) =>
  request({
    url: http,
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: form,
    onUploadProgress: onUploadProgress
  })
// 下载文件
export const getFileApi = (http, query) =>
  request({
    url: http,
    method: 'get',
    params: query
  })

export function fetchList(query) {
  return request({
    url: '/dr/drdatares/page',
    method: 'get',
    params: query
  })
}

export function addObj(obj) {
  return request({
    url: '/dr/drdatares',
    method: 'post',
    data: obj
  })
}

export function getObj(id) {
  return request({
    url: '/dr/drdatares/' + id,
    method: 'get'
  })
}

export function delObj(id) {
  return request({
    url: '/dr/drdatares/' + id,
    method: 'delete'
  })
}

export function putObj(obj) {
  return request({
    url: '/dr/drdatares',
    method: 'put',
    data: obj
  })
}

export const uploadUrl = {
  gitInfoUrl: '/dr/drdatares/getinfo'
}

// 获取资源列表
export const fetchFileList = (query) =>
  request({
    url: '/dr/drdatares/page',
    method: 'get',
    params: query
  })

// 删除文件
export const delFile = (id) =>
  request({
    url: '/dr/drdatares/' + id,
    method: 'delete'
  })

// 上传单附件，可为独立(或批量)附件或数字资源
export const getDRAttachInfos = (query) =>
  request({
    url: '/dr/drdatares/getinfo',
    method: 'get',
    params: query
  })

// 批量上传数字资源
export const uploaddrs = (obj) =>
  request({
    url: '/dr/drdatares/uploaddrs',
    method: 'post',
    data: obj
  })

// 批量上传数字资源文件
export const uploadattachs = (obj) =>
  request({
    url: '/dr/drdatares/uploadattachs',
    method: 'post',
    data: obj
  })

// 设置数字资源属主封面图片 get id: 资源dataresId
export const setOwnerFace = (id) =>
  request({
    url: '/dr/drdatares/setownerface/' + id,
    method: 'get'
  })

// 获取数字资源属主封面图片 get id:主体ownerId，type主体类型ownerType
export const getOwnerFace = (id, type) =>
  request({
    url: `/dr/drdatares/getownerface/${type}/${id}`,
    method: 'get'
  })
