import { request } from 'umi';
import type {
  MemberTableListItem,
  AddressTableListParams,
  LoginLogListParams,
  SubListParams
} from './data';
import service from '@/services/http/service';


export async function querySubAllList(params: SubListParams) {

  console.log("querySubAllList: ", params)
  let result = await service.post('/api/v1/sub/list/all', {
    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 queryPushedList(params: SubListParams) {

  console.log("queryPushedList: ", params)
  let result = await service.post('/api/v1/sub/list/pushed', {
    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 queryTodayList(params: SubListParams) {

  console.log("queryTodayList: ", params)
  let result = await service.post('/api/v1/sub/list/today', {
    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 newsPublishSub(id: number) {

  console.log("newsPublishSub: ", id)
  let result = await service.post('/api/v1/news/publish', {
    "id": id,
  });


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




export async function removeMember(params: { ids: number[] }) {
  return request('/api/member/member/delete', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function updateMember(params: MemberTableListItem) {
  return request('/api/member/member/update', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function queryAddress(params: AddressTableListParams) {
  return request('/api/member/address/list', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function queryLoginLog(params: LoginLogListParams) {
  return request('/api/member/loginlog/list', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}
