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

export async function queryMemberList(params: MemberTableListParams) {
  if (params.status != null) {
    params.status = Number(params.status)
  }
  return request('/api/member/member/list', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

// "id": 1,
// "user_name": "weizihuaing@163.com",
// "user_alias": "weizihuaing@163.com",
// "password": "e10adc3949ba59abbe56e057f20f883e",
// "first_name": "",
// "last_name": "",
// "title": "",
// "company": "",
// "salt": "",
// "phone_number": "",
// "is_admin": false,
// "email": "weizihuaing@163.com",
// "address": "",
// "remark": "",
// "deleted": false,
// "state": 1,
// "is_subscribed": false,
// "login_ip": "38.150.11.190",
// "login_time": 1710918972,
// "create_user": "admin",
// "edit_user": "admin",
// "created_time": "2024-03-20 14:35:07",
// "updated_time": "2024-03-20 15:16:12",
// "extra_data": {}
export async function queryMemberListV2(params: MemberTableListParamsV2) {

  console.log("queryMemberListV2: ", params)
  let result = await service.post('/api/v1/customer/list', {
    "email": params.email,
    "page_no": params.current,
    "page_size": params.pageSize
  });

  return Promise.resolve({
    data: result.data.list,
    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,
    },
  });
}
