/**
 * 用户信息相关接口
 */
import type { CouponBean, LoginParams, LoginResult, RegisterParams, TerminalBean } from './types';
import { get, post } from '@/utils/request';
import { UserBean } from '@/store/modules/user/types';

enum URL {
  // login = '/member/login',
  login = '/wc/wechat/LoginByMa',
  loginByCode = '/wc/wechat/LoginByMaCode',
  register = '/wc/wechat/register',
  uploadAvatar = '/wc/wechat/uploadImage',
  logout = '/user/logout',
  // profile = '/user/profile',
  profile = 'wc/wechat/member_detail',

  // wc/wechat/member_detail
  addressList = '/ext/addr/list',
  addressDetail = '/ext/addr/find',
  addressCreate = '/ext/addr/create',
  addressUpdate = '/ext/addr/update',
  addressDelete = '/ext/addr/delete',
  dynamicCode = '/member/dynccode',
  rechargeList = '/ext/recharge/rule_config',
  recharge = '/memberIncoming/wx_save',
  couponList = '/wechat/coupons/coupons/pageList',
  integralList = '/ext/member/integral_query',
  terminal = 'wechat/coupons/terminal?companyId='
}

export const getUserProfile = () => get<UserBean>({ url: URL.profile });
export const login = (data: LoginParams) => post<LoginResult>({ url: URL.login, data });
export const loginByCode = (code: string, companyId: string) => post<any>({ url: URL.loginByCode + `?code=${code}` });

export const register = (data: RegisterParams) => post<LoginResult>({ url: URL.register, data });

export const logout = () => post<any>({ url: URL.logout });

export const getAddressList = () => get<any>({ url: URL.addressList });
export const getAddressDetail = (id: string) => get<any>({ url: URL.addressDetail + `?id=${id}` });

export const addressCreate = (data: any) => post<any>({ url: URL.addressCreate, data });
export const addressUpdate = (data: any) => post<any>({ url: URL.addressUpdate, data });
export const addressDelete = (id: string) => post<any>({ url: URL.addressDelete + `?id=${id}` });

export const getDynamicCode = () => post<any>({ url: URL.dynamicCode });

export const getRechargeList = () => get<any>({ url: URL.rechargeList });

export const recharge = (data: any) => post({ url: URL.recharge, data });

export const getCouponList = (data: any) => post<CouponBean[]>({ url: URL.couponList, data });

export const getIntegralList = (data: any) => get({ url: URL.integralList, data });

export const getTerminal = (companyId: string) => get<TerminalBean>({ url: URL.terminal + companyId });
