import axios from 'axios';
import qs from 'query-string';
import type { CommonNumIdParams, CommonResult } from './common';

export type merchantDeployRate = {
  factLabel: number; // 淘宝售价
  showLabel: number; // 卡片面值
  platformLabel: string;
  isLinkSingle: boolean;
  value: number;
  linkID: string;
  platformFee: number;
  sort?: number;
};

export type simpleArray = {
  label: string;
  value: any;
  isLink?: boolean;
};

export type merchantDeployRecord = {
  id: number;
  status: string;
  merchantUid: string;
  payType: string;
  payTypeName: string;
  singleRoadUid: string;
  singleRoadName: string;
  singleRoadPlatformRate: merchantDeployRate[];
  singleRoadAgentRate: number;
  rollRoadCode: string;
  rollRoadName: string;
  rollRoadPlatformRate: number;
  rollRoadAgentRate: number;
  autoPayfor: string;
  autoSettle: string;
  restrictArea: string[];
  isRestrictAgent: boolean;
  isRestrictCardPass: boolean;
  isRestrictInternalIp: boolean;
  isRestrictIp: boolean;
  isRestrictDevice: boolean;
  submitStrategy: string;
};

export type merchantDeployAddRecord = {
  merchantUid: string;
  singleRoadUid: string;
  submitStrategy: string;
  singleRoadPlatformRate: merchantDeployRate[];
  singleRoadAgentRate: number;
  autoSettle: string;
  autoPayfor: string;
  rollRoadCode: string;
  rollRoadPlatformRate: number;
  rollRoadAgentRate: number;
  restrictArea: string[];
  isRestrictAgent: boolean;
  isRestrictCardPass: boolean;
  isRestrictInternalIp: boolean;
  isRestrictIp: boolean;
  isRestrictDevice: boolean;
};

export type merchantDeployAddRecordWithID = merchantDeployAddRecord &
  CommonNumIdParams;

export function getmerchantDeployList(params: { merchantUid: string }) {
  return axios.get<CommonResult<merchantDeployRecord>>(
    '/api/merchant/deploy/getList',
    {
      params,
      paramsSerializer: obj => {
        return qs.stringify(obj);
      }
    }
  );
}

export function deleteMerchantDeploy(params: {
  merchantUid: string;
  payType: string;
  singleRoadUid: string;
}) {
  return axios.delete('/api/merchant/deploy/delete', { params });
}

export function addMerchantDeploy(data: merchantDeployAddRecord) {
  return axios.post('/api/merchant/deploy/add', data);
}

export function updateMerchantDeploy(data: merchantDeployAddRecordWithID) {
  return axios.post('/api/merchant/deploy/update', data);
}

export function getMerchantDeployDetail(params: { id: number }) {
  return axios.get<merchantDeployRecord>('/api/merchant/deploy/getDetail', {
    params,
    paramsSerializer: obj => {
      return qs.stringify(obj);
    }
  });
}

export default null;

export function queryAllRestrictArea() {
  return axios.get<CommonResult<string>>(
    '/api/restriction/location/getAllProvince'
  );
}
