'use server'
import {PageRecord} from '@/lib/api'
import {callByUser} from '@/actions/base'

type Whitelist = {
  id: number
  host: string
  created_at: string
  updated_at: string
  remark: string
}

async function listWhitelist(props: {
  page: number
  size: number
}) {
  return await callByUser<PageRecord<Whitelist>>('/api/whitelist/list', props)
}

async function createWhitelist(props: {
  host: string
  remark?: string
}) {
  console.log(props)
  return await callByUser('/api/whitelist/create', props)
}

async function updateWhitelist(props: {
  id: number
  host?: string
  remark?: string
}) {
  console.log(props)
  return await callByUser('/api/whitelist/update', props)
}

async function removeWhitelist(props: {
  id: number
}[]) {
  return await callByUser('/api/whitelist/remove', props)
}

export {
  listWhitelist,
  createWhitelist,
  updateWhitelist,
  removeWhitelist,
  type Whitelist,
}
