import { api } from './client'

export async function updateAdminUsername(newUsername) {
  const { data } = await api.put('/admin/username', { new_username: newUsername })
  return data
}

export async function updateAdminPassword(payload = {}) {
  const currentPassword = String(payload.currentPassword || '')
  const newPassword = String(payload.newPassword || '')
  const { data } = await api.put('/admin/password', {
    current_password: currentPassword,
    new_password: newPassword,
  })
  return data
}

export async function logout() {
  const { data } = await api.post('/logout')
  return data
}

export async function fetchAdminPasskeys() {
  const { data } = await api.get('/admin/passkeys')
  return data
}

export async function createAdminPasskeyOptions(payload = {}) {
  const { data } = await api.post('/admin/passkeys/register/options', payload)
  return data
}

export async function createAdminPasskeyVerify(payload = {}) {
  const { data } = await api.post('/admin/passkeys/register/verify', payload)
  return data
}

export async function deleteAdminPasskey(passkeyId) {
  const { data } = await api.delete(`/admin/passkeys/${passkeyId}`)
  return data
}

export async function reportAdminPasskeyClientError(payload = {}) {
  const { data } = await api.post('/admin/passkeys/client-error', payload)
  return data
}
