import { http } from './client'
import type { Tag } from '@/types'

export interface CreateTagRequest {
  name: string
  color?: string
  icon?: string
}

export interface UpdateTagRequest {
  name?: string
  color?: string
  icon?: string
  order?: number
}

export const tagApi = {
  /**
   * 获取标签列表
   */
  async getTags() {
    return http.get<Tag[]>('/tags')
  },

  /**
   * 获取标签详情
   */
  async getTag(id: string) {
    return http.get<Tag>(`/tags/${id}`)
  },

  /**
   * 创建标签
   */
  async createTag(data: CreateTagRequest) {
    return http.post<Tag>('/tags', data)
  },

  /**
   * 更新标签
   */
  async updateTag(id: string, data: UpdateTagRequest) {
    return http.put<Tag>(`/tags/${id}`, data)
  },

  /**
   * 删除标签（通过 ID）
   */
  async deleteTag(id: string) {
    return http.delete<number>(`/tags/${id}`)
  },

  /**
   * 合并标签（使用标签 ID）
   */
  async mergeTags(sourceTagIds: string[], targetTagId: string) {
    return http.post<number>('/tags/merge', { sourceTagIds, targetTagId })
  }
}
