import request from './request'
import type {
  Tag,
  CreateTagRequest,
  UpdateTagRequest,
  TagFilter,
  ReorderTagsRequest,
  PaginatedResult,
} from '@/types'

export const tagsApi = {
  // Get tags list
  getTagsList: (params: TagFilter) => {
    return request.get<any, PaginatedResult<Tag>>('/tags', { params })
  },

  // Get tag by id
  getTagById: (id: string) => {
    return request.get<any, Tag>(`/tags/${id}`)
  },

  // Create tag
  createTag: (data: CreateTagRequest) => {
    return request.post<any, Tag>('/tags', data)
  },

  // Update tag
  updateTag: (id: string, data: UpdateTagRequest) => {
    return request.patch<any, Tag>(`/tags/${id}`, data)
  },

  // Delete tag
  deleteTag: (id: string) => {
    return request.delete(`/tags/${id}`)
  },

  // Reorder tags (and/or move across groups)
  reorderTags: (data: ReorderTagsRequest) => {
    return request.patch('/tags/sort', data)
  },
}