import { request } from 'umi';
import type {
  AddressTableListParams,
  LoginLogListParams,
  NewsListParams,
  NewsParams,
  QAParams
} from './data';
import service from '@/services/http/service';



export async function queryAQAllList(params: QAParams) {

  console.log("queryAQAllList: ", params)
  let result = await service.post('/api/v1/qa/list', {
    all: true,
    tag: params.tag,
    order_asc: params.order_asc,
    is_deleted: params.is_deleted,
    search: params.main_title,
    "page_no": params.currentPage! - 1,
    "page_size": params.pageSize
  });

  return Promise.resolve({
    data: result,
    success: true,
  })
}


export async function queryQADraftList(params: QAParams) {

  console.log("queryQADraftList: ", params)
  let result = await service.post('/api/v1/qa/draft/list', {
    tag: params.tag,
    order_asc: params.order_asc,
    search: params.main_title,
    "page_no": params.currentPage! - 1,
    "page_size": params.pageSize
  });

  return Promise.resolve({
    data: result,
    success: true,
  })
}

export async function queryDeleteList(params: QAParams) {

  console.log("queryDeleteList: ", params)
  let result = await service.post('/api/v1/sub/list/today', {
    "page_no": params.currentPage,
    "page_size": params.pageSize
  });


  return Promise.resolve({
    data: result,
    success: true,
  })
}


export async function removeQA(params: { ids: number[] }) {

  console.log("removeQA: ", params)

  let result = await service.post('/api/v1/qa/delete', {
    ids: params.ids,
  });

  return Promise.resolve({
    data: result,
    success: true,
  })

}


export async function removeQADraft(params: { ids: number[] }) {

  console.log("removeQADraft: ", params)

  let result = await service.post('/api/v1/qa/draft/delete', {
    ids: params.ids,
  });

  return Promise.resolve({
    data: result,
    success: true,
  })

}


// 通过模版copy至草稿箱
export async function copyQAItem(params: QAParams) {

  console.log("editNewsItem: ", params)
  let result = await service.post('/api/v1/qa/edit', {
    ...params
  });

  return Promise.resolve({
    data: result.data.draft_id,
    success: true,
  })
}