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

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

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

/**
 * 添加过滤条件
 * @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: 'get',
    params,
  })
}

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

/**
 * 设置筛选
 * @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 },
  })
}

/**
 *
 * 获取用户选择的筛选选项
 * @param reviewType 类型
 * @param userId 用户
 * @returns
 */
 export async function getfieldList(reviewType: number, userId: number): Promise<void> {
  return http.request({
    url: `/ocr/user/field/queryFields`,
    method: 'get',
    params: { reviewType, userId },
  })
}
/**
 *
 * 获取所有筛选选项列表
 * @param reviewType 类型
 * @returns
 */
 export async function getAllfieldList(reviewType: number): Promise<void> {
  return http.request({
    url: `/ocr/field/list`,
    method: 'get',
    params: { reviewType},
  })
}

/**
 *
 * 新增或修改用户筛选信息
 * @param reviewType 类型
 * @param userId 用户
 * @param userField 用户动态字段列表（用逗号分隔的字符串）
 * 
 * @returns
 */
 export async function savefield(reviewType: number,userId:string,userFieldFixed:string,userFieldUnFixed:string=''): Promise<void> {
  return http.request({
    url: `/ocr/user/field/saveOrUpdate`,
    method: 'POST',
    params: { reviewType,userId,userFieldFixed,userFieldUnFixed},
  })
}




