import { api } from './client'

export async function getDashboard() {
  const { data } = await api.get('/admin/security/dashboard')
  return data
}

export async function getThreats(params) {
  const { data } = await api.get('/admin/security/threats', { params })
  return data
}

export async function getBannedIps() {
  const { data } = await api.get('/admin/security/banned-ips')
  return data
}

export async function getBannedUsers() {
  const { data } = await api.get('/admin/security/banned-users')
  return data
}

export async function banIp(payload) {
  const { data } = await api.post('/admin/security/ban-ip', payload)
  return data
}

export async function unbanIp(ip) {
  const { data } = await api.post('/admin/security/unban-ip', { ip })
  return data
}

export async function banUser(payload) {
  const { data } = await api.post('/admin/security/ban-user', payload)
  return data
}

export async function unbanUser(userId) {
  const { data } = await api.post('/admin/security/unban-user', { user_id: userId })
  return data
}

export async function getIpRisk(ip) {
  const safeIp = encodeURIComponent(String(ip || '').trim())
  const { data } = await api.get(`/admin/security/ip-risk/${safeIp}`)
  return data
}

export async function clearIpRisk(ip) {
  const { data } = await api.post('/admin/security/ip-risk/clear', { ip })
  return data
}

export async function getUserRisk(userId) {
  const safeUserId = encodeURIComponent(String(userId || '').trim())
  const { data } = await api.get(`/admin/security/user-risk/${safeUserId}`)
  return data
}

export async function cleanup() {
  const { data } = await api.post('/admin/security/cleanup', {})
  return data
}
