import { publicApi } from './http'

export async function fetchUserEmail() {
  const { data } = await publicApi.get('/user/email')
  return data
}

export async function bindEmail(payload) {
  const { data } = await publicApi.post('/user/bind-email', payload)
  return data
}

export async function unbindEmail() {
  const { data } = await publicApi.post('/user/unbind-email', {})
  return data
}

export async function fetchEmailNotify() {
  const { data } = await publicApi.get('/user/email-notify')
  return data
}

export async function updateEmailNotify(payload) {
  const { data } = await publicApi.post('/user/email-notify', payload)
  return data
}

export async function changePassword(payload) {
  const { data } = await publicApi.post('/user/password', payload)
  return data
}

export async function fetchKdocsSettings() {
  const { data } = await publicApi.get('/user/kdocs')
  return data
}

export async function updateKdocsSettings(payload) {
  const { data } = await publicApi.post('/user/kdocs', payload)
  return data
}

export async function fetchKdocsStatus() {
  const { data } = await publicApi.get('/kdocs/status')
  return data
}

export async function fetchUserPasskeys() {
  const { data } = await publicApi.get('/user/passkeys')
  return data
}

export async function createUserPasskeyOptions(payload) {
  const { data } = await publicApi.post('/user/passkeys/register/options', payload)
  return data
}

export async function createUserPasskeyVerify(payload) {
  const { data } = await publicApi.post('/user/passkeys/register/verify', payload)
  return data
}

export async function deleteUserPasskey(passkeyId) {
  const { data } = await publicApi.delete(`/user/passkeys/${passkeyId}`)
  return data
}

export async function reportUserPasskeyClientError(payload) {
  const { data } = await publicApi.post('/user/passkeys/client-error', payload || {})
  return data
}

export async function fetchSocialBindings() {
  const { data } = await publicApi.get('/user/social-bindings')
  return data
}

export async function bindSocial(payload) {
  const { data } = await publicApi.post('/user/social-bindings', payload || {})
  return data
}

export async function unbindSocial(provider) {
  const { data } = await publicApi.delete(`/user/social-bindings/${encodeURIComponent(provider)}`)
  return data
}
