import { customerFetch, ResponseDataEntity, oldBaseFetch } from '.';

export class LoginParams {
  /** 登陆标识 */
  code?: string;
  /** 账号 */
  loginAccount?: string;
  /** 密码 */
  password?: string;
}
export const appLogin = (data: LoginParams) =>
  customerFetch({
    url: '/dcxy/wechat/applet/login/',
    method: 'POST',
    data: data,
  });

export const appLogout = () =>
  customerFetch({
    url: '/dcxy/wechat/applet/login/out',
  });

export class PwdParams {
  /** 账号 */
  loginAccount: string;
  /** 密码 */
  password: string;
  /** 验证码 */
  verification: string;
}
export const changePwdByCellphone = (data: PwdParams) =>
  customerFetch({
    url: '/app/customer/forget/pwd',
    method: 'POST',
    data: data,
  });

type RegisiterPramas = {
  code: string;
  areaId: number;
  areaName: string;
  customerName: string;
  customerPhone: string;
  customerSex: string;
  password: string;
  verificationCode: string;
};
// type RegisiterReponseData = {};

export const wxUserRegister = (entity: RegisiterPramas) =>
  oldBaseFetch({
    // url: '/dcxy/wechat/applet/register/',
    url: '/dcxy/api/customer/wxmini/register',
    method: 'POST',
    data: entity,
  });

type perfectionCustomerParams = {
  birthDay?: string;
  customerHead?: string;
  customerId: number;
  customerName: string;
  customerSex: string;
  email?: string;
  entranceDate?: string;
  idCard?: string;
  studentNo?: string;
};

export const perfectionUserInfo = (entity: perfectionCustomerParams) =>
  customerFetch({
    url: '/dcxy/wechat/applet/perfection/customer',
    method: 'POST',
    data: entity,
  });

type CustomerParam = {
  areaId: number;
  areaName: string;
  customerId: number;
  customerName: string;
  customerPhone: string;
  feedbackContent: string;
};
export const fetchFeedback = (entity: CustomerParam) =>
  customerFetch({
    url: '/app/customer/feed/back',
    method: 'POST',
    data: entity,
  });

export const refreshCodeBar = (): Promise<ResponseDataEntity<string>> =>
  customerFetch({
    url: '/dcxy/wechat/applet/flush/idbar',
  });

type ChangeAppPasswordParam = {
  customerId: number;
  oldPassword: string;
  password: string;
};
export const changeAppPassword = (
  entity: ChangeAppPasswordParam,
): Promise<ResponseDataEntity<null>> =>
  customerFetch({
    url: '/app/customer/old/pwd',
    method: 'POST',
    data: entity,
  });

export const changeDevicePassword = (
  entity: ChangeAppPasswordParam,
): Promise<ResponseDataEntity<null>> =>
  customerFetch({
    url: '/app/customer/hardware/pwd',
    method: 'POST',
    data: entity,
  });
type ChangePhoneAccountParams = {
  customerId: number;
  password: string;
  phoneAccount: string;
  verification: string;
};
export const changePhoneAccount = (
  entity: ChangePhoneAccountParams,
): Promise<ResponseDataEntity<null>> =>
  customerFetch({
    url: '/app/customer/phone/account/',
    method: 'POST',
    data: entity,
  });
type SwitchAccountLoginStateParams = {
  customerId: number;
  state: string;
};
export const switchAccountLoginState = (
  entity: SwitchAccountLoginStateParams,
): Promise<ResponseDataEntity<null>> =>
  customerFetch({
    url: `/app/customer/switch/${entity.customerId}/${entity.state}`,
    method: 'PUT',
  });

type FetchBalanceStateParams = {
  customerId: number;
};
export enum BalanceState {
  open = 1,
  close = 0,
}
export const fetchBalanceState = (
  entity: FetchBalanceStateParams,
): Promise<ResponseDataEntity<BalanceState>> =>
  customerFetch({
    url: '/app/customer/balance/state',
    data: entity,
  });
type SwitchBalanceStateParams = {
  customerId: number;
  isEnabled: BalanceState;
};
export const switchBalanceState = (
  entity: SwitchBalanceStateParams,
): Promise<ResponseDataEntity<null>> =>
  customerFetch({
    url: `/app/customer/swich/balance/${entity.customerId}/${entity.isEnabled}`,
    method: 'PUT',
  });

type FetchAppLaunchCustomerParams = {
  secretCode: string;
  uuId: string;
  serviceId: string;
  timeStamp: string;
  sign: string;
};
export const fetchAppLaunchCustomer = (entity: FetchAppLaunchCustomerParams) =>
  customerFetch({
    url: '/dcxy/wechat/anxinpay/app/jump/mini/validatelogin',
    data: entity,
  });
