import request from '@/utils/request'

// 查询呼叫接口列表（admin专用，走 /admin/ 前缀，路由到 fs-admin 8004）
export function listCompanyVoiceApi(query) {
  return request({
    url: '/admin/voice-api/list',
    method: 'get',
    params: query
  })
}
export function getVoiceApiList() {
  return request({
    url: '/admin/voice-api/list',
    method: 'get'
  })
}


// 查询呼叫接口详细
export function getCompanyVoiceApi(apiId) {
  return request({
    url: '/admin/voice-api/' + apiId,
    method: 'get'
  })
}

// 新增呼叫接口
export function addCompanyVoiceApi(data) {
  return request({
    url: '/company/companyVoiceApi',
    method: 'post',
    data: data
  })
}

// 修改呼叫接口
export function updateCompanyVoiceApi(data) {
  return request({
    url: '/company/companyVoiceApi',
    method: 'put',
    data: data
  })
}

// 删除呼叫接口
export function delCompanyVoiceApi(apiId) {
  return request({
    url: '/company/companyVoiceApi/' + apiId,
    method: 'delete'
  })
}

// 导出呼叫接口
export function exportCompanyVoiceApi(query) {
  return request({
    url: '/company/companyVoiceApi/export',
    method: 'get',
    params: query
  })
}

// ========== 通话接口-租户分配 ==========

// 查询接口已分配的租户列表
export function getAssignedTenants(apiId) {
  return request({
    url: '/admin/voice-api/tenants/' + apiId,
    method: 'get'
  })
}

// 查询租户已分配的接口列表
export function getTenantApis(companyId) {
  return request({
    url: '/admin/voice-api/apis/' + companyId,
    method: 'get'
  })
}

// 分配接口给租户（批量）
export function assignTenants(apiId, companyIds) {
  return request({
    url: '/admin/voice-api/assignTenants',
    method: 'post',
    data: { apiId, companyIds }
  })
}

// 取消分配
export function unassignTenant(apiId, companyId) {
  return request({
    url: '/admin/voice-api/unassignTenant',
    method: 'delete',
    params: { apiId, companyId }
  })
}

// 查询接口已分配租户数量
export function getTenantCount(apiId) {
  return request({
    url: '/admin/voice-api/tenantCount/' + apiId,
    method: 'get'
  })
}

// ========== 租户定价管理 ==========

// 查询租户-接口定价列表（分页）
export function listVoiceApiTenant(query) {
  return request({
    url: '/admin/voice-api/tenant/list',
    method: 'get',
    params: query
  })
}

// 更新租户定价
export function updateTenantPricing(data) {
  return request({
    url: '/admin/voice-api/tenant/update',
    method: 'put',
    data: data
  })
}