import request, { IWorkspaceResponse } from '/@/api/http/request'
import { mapLayers } from '/@/constants/mock-layers'
import { elementGroupsReq, PostElementsBody, PutElementsBody } from '/@/types/mapLayer'
import { getWorkspaceId } from '/@/utils/index';

const PREFIX = '/map/api/v1'

type UnknownResponse = Promise<IWorkspaceResponse<unknown>>

export const getLayers = async (reqParams: elementGroupsReq): UnknownResponse => {
  return mapLayers
}

// Get elements groups request
export const getElementGroupsReq = async (body: elementGroupsReq): Promise<IWorkspaceResponse<any>> => {
  const url = `${PREFIX}/workspaces/` + getWorkspaceId() + '/element-groups'
  const result = await request.get(url, body)
  return result.data
}
// add element
export const postElementsReq = async (pid: string, body: PostElementsBody): Promise<IWorkspaceResponse<{ id: string }>> => {
  const url = `${PREFIX}/workspaces/` + getWorkspaceId() + `/element-groups/${pid}/elements`
  const result = await request.post(url, body)
  return result.data
}
// Update map element request
export const updateElementsReq = async (id: string, body: PutElementsBody): Promise<IWorkspaceResponse<{ id: string }>> => {
  const url = `${PREFIX}/workspaces/` + getWorkspaceId() + `/elements/${id}`
  const result = await request.put(url, body)
  return result.data
}
// Delete map element
export const deleteElementReq = async (id: string, body: {}): Promise<any> => {
  const url = `${PREFIX}/workspaces/` + getWorkspaceId() + `/elements/${id}`
  const result = await request.delete(url, body)
  return result.data
}

// Delete layer elements
export const deleteLayerEleReq = async (id: string, body: {}): Promise<any> => {
  const url = `${PREFIX}/workspaces/` + getWorkspaceId() + `/element-groups/${id}/elements`
  const result = await request.delete(url, body)
  return result.data
}