import { http } from '@/utils/http/axios'
import type { FilterCondition, FilterParam, FilterSearchParam, FilterUpdate, PageParam } from '/#/api'

/**
 * 获取过滤条件列表
 * @param params
 * @returns 1
 */
export async function getConditionList(params: PageParam & FilterSearchParam): Promise<any> {
  const res = await http.request({
    url: `/ocr/ocrUsersearch/list`,
    method: 'get',
    params,
  })

  const { data: { records, pages } } = res
  return {
    pageCount: pages,
    data: records,
  }
}

/**
 * 添加过滤条件
 * @param params
 */
export async function addCondition(params: FilterCondition) {
  return http.request({
    url: `/ocr/ocrUsersearch/add`,
    method: 'post',
    params,
  })
}

/**
 * 编辑过滤条件
 * @param params
 * @returns
 */
export async function updateCondition(params: FilterUpdate) {
  return http.request({
    url: `/ocr/ocrUsersearch/edit`,
    method: 'post',
    params,
  })
}

/**
 * 删除过滤条件
 * @param params
 * @returns
 */
export async function deleteCondition(params: { ids: string }) {
  return http.request({
    url: `/ocr/ocrUsersearch/deleteBatch`,
    method: 'delete',
    params,
  })
}

/**
 * 获取设置为显示的筛选
 * @returns
 */
export async function getFilter(): Promise<any> {
  return http.request({
    url: `/ocr/ocrSearchmanager/query`,
    method: 'get',
  })
}

/**
 * 设置筛选
 * @param params
 * @returns
 */
export async function setFilter(params: FilterParam): Promise<void> {
  return http.request({
    url: `/ocr/ocrSearchmanager/add`,
    method: 'post',
    params,
  })
}

/**
 * 收藏
 * @param params
 * @returns
 */
export async function favorite(searchid: string): Promise<void> {
  return http.request({
    url: `/ocr/ocrUsersearch/collect`,
    method: 'get',
    params: { searchid },
  })
}

/**
 * 取消收藏
 * @param params
 * @returns
 */
export async function unfavorite(searchid: string): Promise<void> {
  return http.request({
    url: `/ocr/ocrUsersearch/collectreset`,
    method: 'get',
    params: { searchid },
  })
}

/**
 *
 * @param searchid 拖拽的id
 * @param reorder 拖拽后的排序
 * @returns
 */
export async function sort(searchid: string, reorder: number): Promise<void> {
  return http.request({
    url: `/ocr/ocrUsersearch/reorder`,
    method: 'get',
    params: { searchid, reorder },
  })
}
