import request from '../utils/request'

// ========== 标签组 ==========

export function getTagGroups() {
  return request.get('/tags/groups')
}

export function createTagGroup(data) {
  return request.post('/tags/groups', data)
}

export function editTagGroup(id, data) {
  return request.post(`/tags/groups/${id}/edit`, data)
}

export function deleteTagGroup(id) {
  return request.post(`/tags/groups/${id}/delete`)
}

// ========== 标签节点 ==========

export function getTags(groupId) {
  return request.get(`/tags/groups/${groupId}/tags`)
}

export function createTag(groupId, data) {
  return request.post(`/tags/groups/${groupId}/tags`, data)
}

export function editTag(id, data) {
  return request.post(`/tags/${id}/edit`, data)
}

export function deleteTag(id) {
  return request.post(`/tags/${id}/delete`)
}

export function moveTag(id, data) {
  return request.post(`/tags/${id}/move`, data)
}

// ========== 导入导出 ==========

export function exportTags() {
  return request.get('/tags/export')
}

export function importTags(data) {
  return request.post('/tags/import', data)
}

// ========== 打标 ==========

export function setEntityTags(entityType, entityId, tagIds) {
  return request.post('/tags/assignments', { entityType, entityId, tagIds })
}

export function getEntityTags(entityType, entityId) {
  return request.get('/tags/assignments', { params: { entityType, entityId } })
}

/**
 * 获取所有标签组及其全部标签（扁平列表），用于标签选择器
 */
export function getAllTagsForSelector() {
  return request.get('/tags/all-with-tags')
}
