import { get, post } from '../utils/request';

export interface MerchantConfigQuery {
	merchant_id?: string;
	scene?: string;
}

export interface CashierOrderPayload {
	merchant_id?: string;
	amount: string;
	remark?: string;
	house_id?: string;
}

export interface CashierOrderResult {
	order_id: string;
}

export interface CashierPayResult {
	timeStamp: string;
	nonceStr: string;
	package: string;
	signType: string;
	paySign: string;
}

export interface BoundMerchantInfo {
	merchant_id?: string;
	merchant_name?: string;
	config?: {
		score_name?: string;
	};
	merchant?: {
		merchant_id?: string;
		merchant_name?: string;
		config?: {
			score_name?: string;
		};
	};
	supplier?: {
		give_rate?: string | number;
	};
	give_rate?: string | number;
}

export interface SupplierInfo {
	supplier_id?: string | number;
	supplier_name?: string;
	logo?: string;
}

export interface ApiResult<T = any> {
	code: number | string;
	msg?: string;
	data?: T;
}

export interface TradeQueryResult {
	order_id?: number | string;
	trade_no?: string;
	pay_status?: number;
	pay_type?: number;
	total_money?: string;
	reduce_money?: string;
	real_money?: string;
}

export const merchantConfig = (data: MerchantConfigQuery = {}) => get<ApiResult>('v1/cashier/merchant', data);

export const createCashierOrder = (data: CashierOrderPayload) =>
	post<ApiResult<CashierOrderResult>>('v1/cashier/order/create', data);

export const cashierPay = (data: { order_id: string }) => post<ApiResult<CashierPayResult>>('v1/cashier/pay', data);

export const cashierRecordList = (data: any = {}) => get('v1/cashier/records', data);

export const bindMerchantByUrl = (url: string) =>
	get<ApiResult<BoundMerchantInfo>>('user/v1/bing.merchant', { url });

export const supplierByUrl = (url: string) =>
	get<ApiResult<SupplierInfo>>('user/v1/supplier', { url });

export const queryTrade = (tradeNo: string) =>
	get<ApiResult<TradeQueryResult>>('user/v1/trade/query', { trade_no: tradeNo });

export const cancelTrade = (tradeNo: string) =>
	get<ApiResult>('user/v1/trade/cancel', { trade_no: tradeNo });
