import { defineStore } from 'pinia'
import { AxiosWrapper } from '@/utils/axios-wrapper'
const url = '/tool'
const axios = new AxiosWrapper()

export const ToolStore = defineStore('tool', () => {
  const query = async ({ skip = 0, limit = undefined, ...info } = {}) => {
    let cond = {}
    if (skip) cond.skip = skip
    if (limit) cond.limit = limit
    cond = { ...cond, ...info }
    const res = await axios.$get(`${url}/query`, cond)
    return res
  }
  const getCollection = async ({ skip = 0, limit = undefined, ...info } = {}) => {
    let cond = {}
    if (skip) cond.skip = skip
    if (limit) cond.limit = limit
    cond = { ...cond, ...info }
    const res = await axios.$get(`${url}/MyCollection`, cond)
    return res
  }
  const total = async (info) => {
    const res = await axios.$get(`${url}/getTotal`, info)
    return res
  }
  const getTotal = async () => {
    const res = await axios.$get(`${url}/CollectionTotal`)
    return res
  }
  return {
    query,
    total,
    getCollection,
    getTotal
  }
})
