import axios from 'axios';
import qs from 'query-string';
import type { CommonPageResult, CommonNumIdParams } from './common';
import type { UserRecord } from './list';
import type { Pagination } from '@/types/global';

export interface MerchantConfigAddRecord {
  merchantName: string;
  loginAccount: string;
  loginPassword: string;
  remark: string;
  status: string;
}

export interface MerchantConfigResRecord extends CommonNumIdParams {
  status: string;
  belongAgentUid: string;
  belongAgentName: string;
  merchantName: string;
  merchantUid: string;
  merchantKey: string;
  merchantSecret: string;
  loginAccount: string;
  whiteIps: string;
  remark: string;
  singlePayForRoadUid: string;
  singlePayForRoadName: string;
  rollPayForRoadCode: string;
  rollPayForRoadName: string;
  payforFee: number;
  updateTime: string;
  createTime: string;
}

export interface MerchantConfigDetailRecord {
  loginAccount: string;
  merchantName: string;
  merchantUid: string;
  whiteIps: string;
  remark: string;
}

export interface MerchantConfigParams extends Partial<UserRecord>, Pagination {}

export function queryMerchantConfigList(params: MerchantConfigParams) {
  return axios.get<CommonPageResult<MerchantConfigResRecord>>(
    '/api/merchant/config/getList',
    {
      params,
      paramsSerializer: obj => {
        return qs.stringify(obj);
      }
    }
  );
}

export function queryMerchant(params: { merchantUid: string }) {
  return axios.get<MerchantConfigDetailRecord>(
    '/api/merchant/config/getDetail',
    {
      params,
      paramsSerializer: obj => {
        return qs.stringify(obj);
      }
    }
  );
}

export function updateMerchantInfo(data: MerchantConfigDetailRecord) {
  return axios.post('/api/merchant/config/updateDetail', data);
}

export function addMerchantConfig(data: MerchantConfigAddRecord) {
  return axios.post('/api/merchant/config/add', data);
}

export function switchMerchantStatus(params: {
  merchantUid: string;
  status: string;
}) {
  return axios.post('/api/merchant/config/switchStatus', params);
}
