import request from '@/utils/request'

// ==================== 方案1：租户字典代管 ====================

export function listTenantDictType(tenantId, query) {
  return request({
    url: '/tenant/dict/type/list',
    method: 'get',
    params: { tenantId, ...query }
  })
}

export function getTenantDictType(tenantId, dictId) {
  return request({
    url: '/tenant/dict/type/' + dictId,
    method: 'get',
    params: { tenantId }
  })
}

export function addTenantDictType(tenantId, data) {
  return request({
    url: '/tenant/dict/type',
    method: 'post',
    params: { tenantId },
    data
  })
}

export function updateTenantDictType(tenantId, data) {
  return request({
    url: '/tenant/dict/type',
    method: 'put',
    params: { tenantId },
    data
  })
}

export function delTenantDictType(tenantId, dictId) {
  return request({
    url: '/tenant/dict/type/' + dictId,
    method: 'delete',
    params: { tenantId }
  })
}

export function listTenantDictData(tenantId, query) {
  return request({
    url: '/tenant/dict/data/list',
    method: 'get',
    params: { tenantId, ...query }
  })
}

export function getTenantDictData(tenantId, dictCode) {
  return request({
    url: '/tenant/dict/data/' + dictCode,
    method: 'get',
    params: { tenantId }
  })
}

export function addTenantDictData(tenantId, data) {
  return request({
    url: '/tenant/dict/data',
    method: 'post',
    params: { tenantId },
    data
  })
}

export function updateTenantDictData(tenantId, data) {
  return request({
    url: '/tenant/dict/data',
    method: 'put',
    params: { tenantId },
    data
  })
}

export function delTenantDictData(tenantId, dictCode) {
  return request({
    url: '/tenant/dict/data/' + dictCode,
    method: 'delete',
    params: { tenantId }
  })
}

export function refreshTenantDictCache(tenantId) {
  return request({
    url: '/tenant/dict/cache/refresh',
    method: 'delete',
    params: { tenantId }
  })
}

// ==================== 方案2：平台字典模板 ====================

export function listTemplateDictType(query) {
  return request({
    url: '/tenant/dict/template/type/list',
    method: 'get',
    params: query
  })
}

export function getTemplateDictType(dictId) {
  return request({
    url: '/tenant/dict/template/type/' + dictId,
    method: 'get'
  })
}

export function addTemplateDictType(data) {
  return request({
    url: '/tenant/dict/template/type',
    method: 'post',
    data
  })
}

export function updateTemplateDictType(data) {
  return request({
    url: '/tenant/dict/template/type',
    method: 'put',
    data
  })
}

export function delTemplateDictType(dictId) {
  return request({
    url: '/tenant/dict/template/type/' + dictId,
    method: 'delete'
  })
}

export function listTemplateDictData(query) {
  return request({
    url: '/tenant/dict/template/data/list',
    method: 'get',
    params: query
  })
}

export function getTemplateDictData(dictCode) {
  return request({
    url: '/tenant/dict/template/data/' + dictCode,
    method: 'get'
  })
}

export function addTemplateDictData(data) {
  return request({
    url: '/tenant/dict/template/data',
    method: 'post',
    data
  })
}

export function updateTemplateDictData(data) {
  return request({
    url: '/tenant/dict/template/data',
    method: 'put',
    data
  })
}

export function delTemplateDictData(dictCode) {
  return request({
    url: '/tenant/dict/template/data/' + dictCode,
    method: 'delete'
  })
}

export function templateDictTypeOptions() {
  return request({
    url: '/tenant/dict/template/type/optionselect',
    method: 'get'
  })
}

export function importTemplateFromPlatform(data) {
  return request({
    url: '/tenant/dict/template/import/platform',
    method: 'post',
    data
  })
}

export function importTemplateFromTenant(data) {
  return request({
    url: '/tenant/dict/template/import/tenant',
    method: 'post',
    data
  })
}

// ==================== 同步下发 ====================

export function runDictSync(data) {
  return request({
    url: '/tenant/dict/sync/run',
    method: 'post',
    data
  })
}

export function getDictSyncTask(taskNo) {
  return request({
    url: '/tenant/dict/sync/task/' + taskNo,
    method: 'get'
  })
}

export function previewDictSync(tenantId, dictTypes) {
  return request({
    url: '/tenant/dict/sync/preview',
    method: 'get',
    params: { tenantId, dictTypes }
  })
}
