import request from '@/utils/http'

const LABEL_OVERRIDE_BASE_URL = '/api/admin/v1/dictionary/label-overrides'

// ==================== 租户端 API ====================

/**
 * 获取当前租户的标签覆盖列表
 */
export function getTenantLabelOverrides() {
  return request.get<Api.Dictionary.LabelOverrideDto[]>({
    url: `${LABEL_OVERRIDE_BASE_URL}/tenant`
  })
}

/**
 * 租户创建/更新标签覆盖
 */
export function upsertTenantLabelOverride(data: Api.Dictionary.UpsertLabelOverrideRequest) {
  return request.post<Api.Dictionary.LabelOverrideDto>({
    url: `${LABEL_OVERRIDE_BASE_URL}/tenant`,
    data
  })
}

/**
 * 租户删除标签覆盖
 */
export function deleteTenantLabelOverride(dictionaryItemId: string) {
  return request.del<void>({
    url: `${LABEL_OVERRIDE_BASE_URL}/tenant/${dictionaryItemId}`
  })
}

// ==================== 平台端 API ====================

/**
 * 获取指定租户的所有标签覆盖（平台管理员用）
 */
export function getPlatformLabelOverrides(
  targetTenantId: string,
  overrideType?: Api.Dictionary.OverrideType
) {
  return request.get<Api.Dictionary.LabelOverrideDto[]>({
    url: `${LABEL_OVERRIDE_BASE_URL}/platform/${targetTenantId}`,
    params: { overrideType }
  })
}

/**
 * 平台强制覆盖租户字典项的标签
 */
export function upsertPlatformLabelOverride(
  targetTenantId: string,
  data: Api.Dictionary.UpsertLabelOverrideRequest
) {
  return request.post<Api.Dictionary.LabelOverrideDto>({
    url: `${LABEL_OVERRIDE_BASE_URL}/platform/${targetTenantId}`,
    data
  })
}

/**
 * 平台删除对租户的强制覆盖
 */
export function deletePlatformLabelOverride(targetTenantId: string, dictionaryItemId: string) {
  return request.del<void>({
    url: `${LABEL_OVERRIDE_BASE_URL}/platform/${targetTenantId}/${dictionaryItemId}`
  })
}
