import { request } from '@umijs/max';
import { PageParams } from './commonType';

export const _getCustomerList = async (
  pageParams: PageParams,
  searchKey: string,
): Promise<API.DefaultObjectResponse> => {
  return request('/api/v1/admin/customer/all', {
    method: 'get',
    params: {
      pageSize: pageParams.pageSize,
      current: pageParams.current,
      searchKey: searchKey,
    },
  });
};

export const _refund = async (data: API.RefundData): Promise<API.DefaultObjectResponse> => {
  return request('/api/v1/admin/customer/refund', {
    method: 'put',
    data,
  });
};

export const _deduct = async (data: API.RefundData): Promise<API.DefaultObjectResponse> => {
  return request('/api/v1/admin/customer/deduction', {
    method: 'put',
    data,
  });
};

export const _bindingIc = async (data: API.BindIcData): Promise<API.DefaultObjectResponse> => {
  return request('/api/v1/admin/customer/bind-ic-card', {
    method: 'put',
    data,
  });
};

export const _getCustomerTopUp = async (id: string): Promise<API.DefaultObjectResponse> => {
  return request('/api/v1/admin/customer/top-up', {
    method: 'get',
    params: {
      id,
    },
  });
};

export const _getCustomerTransactionList = async (
  id: string,
): Promise<API.DefaultObjectResponse> => {
  console.log(id);
  return request(`/api/v1/admin/customer/transaction`, {
    method: 'get',
    params: {
      id,
    },
  });
};

export const _sendCoupon = async (data: API.SendCouponData): Promise<API.DefaultObjectResponse> => {
  data.distributor_type = 'customer';

  return request('/api/v1/admin/coupon/record', {
    method: 'post',
    data,
  });
};

export const _getCouponList = async (): Promise<API.DefaultObjectResponse> => {
  return request('/api/v1/admin/coupon/all', {
    method: 'get',
  });
};
export const _getCouponListByCustomerId = async (
  id: string,
): Promise<API.DefaultObjectResponse> => {
  return request('/api/v1/admin/customer/coupon/all', {
    method: 'get',
    params: {
      id,
    },
  });
};

export const _updateCouponPermission = async (
  data: API.UpdateCouponPermissionData,
): Promise<API.DefaultObjectResponse> => {
  return request('/api/v1/admin/customer/coupon/permission', {
    method: 'put',
    data,
  });
};
export const _getNotifySession = async (id: string): Promise<API.DefaultObjectResponse> => {
  return request(`/api/v1/admin/customer/session`, {
    method: 'get',
    params: {
      id,
    },
  });
};
export const _sendPushNotification = async (
  customerId: string,
  title: string,
  body: string,
): Promise<API.DefaultObjectResponse> => {
  return request('/api/v1/admin/customer/session', {
    method: 'post',
    data: {
      customerId,
      title,
      body,
    },
  });
};
