import { $api } from '@/composables/fetch'
// 基础响应接口
export interface BaseResponse<T = any> {
    code: number;
    data: T;
    msg: string;
}

// 分页请求参数接口
export interface PageParams {
    page: {
        current: number;
        row: number;
    }
    [key: string]: any;
}

// 分页响应接口
export interface PageResponse<T> {
    data: T[];
    code: number;
    msg: string;
    page: {
        current: number;
        pageTotal: number;
        row: number;
        rowTotal: number;
    }
}

// 卡片类型相关接口
export interface CardType {
    id: string;
    name: string;
    [key: string]: any;
}

export interface CardTypeParams extends PageParams {
    name?: string;
    status?: number;
}

// 商户相关接口
export interface MerchantUser {
    id: string;
    username: string;
    [key: string]: any;
}

export interface MerchantAccount {
    balance: number;
    [key: string]: any;
}

export interface MerchantParams extends PageParams {
    username?: string;
    status?: number;
}

// KYC相关接口
export interface KycInfo {
    id: string;
    status: number;
    [key: string]: any;
}

export interface KycParams {
    merchantId: string;
    [key: string]: any;
}

// 卡片相关接口
export interface CardInfo {
    id: string;
    cardNo: string;
    [key: string]: any;
}

export interface CardApplyParams {
    cardTypeId: string;
    [key: string]: any;
}

// 交易相关接口
export interface TransactionInfo {
    id: string;
    amount: number;
    [key: string]: any;
}

export interface TransactionParams extends PageParams {
    cardId?: string;
    type?: number;
}

// 转账相关接口
export interface TransferInfo {
    id: string;
    amount: number;
    [key: string]: any;
}

export interface TransferParams {
    cardId: string;
    uniqueId: string;
    [key: string]: any;
}

// 汇率相关接口
export interface RateInfo {
    fromCurrency: string;
    toCurrency: string;
    rate: number;
}

// 国家城市相关接口
export interface CountryCityInfo {
    code: string;
    cnName: string;
    enName: string;
}

// 代付校验参数
export interface ucardValidateParams{
    bankId: number;
    uniqueId: string;
    originOrderNo: string;
    amount: number;
    postscript: string;
    relationship: string;
    sourceFunds: string;
    payPurpose: string;
    payerType: string;
    payerLastName: string;
    payerFirstName: string;
    payerIdNo: string;
    payerIdNoType: string;
    payerIdCountry: string;
    payerBirthday: string;
    payerNationalityCountry: string;
    payerMobile: string;
    payerCountryCode: string;
    payerCityCode: string;
    payerAddress: string;
    payerPostCode: string;
    payerOccupation: string;
    benAccountNum: string;
    benAccountName: string;
    benCountryCode: string;
    benCityCode: string;
    benAddress: string;
    benPostCode: string;
    benTransBankSwift: string;
    benLastName: string;
    benFirstName: string;
    benNationalityCountry: string;
    benIdNoType: string;
    benIdNo: string;
    benIdExpirationDate: string;
    benBirthday: string;
    benMobileCode: string;
    benMobile: string;
    benBankAccountType: string;
    benBankCode: string;
    payer: ucardValidateParams;
    payee: ucardValidateParams;
}


export const ucardApi = {
    //获取卡片类型列表
    cardTypesList(params: CardTypeParams = { page: { current: 1, row: 10 } }): Promise<BaseResponse<PageResponse<CardType>>> {
        return $api.post("/ucard/api/card/types/page", { ...params});
    },
    // 更新卡片类型列表
    updateCardTypes(params: Partial<CardType> = {}): Promise<BaseResponse> {
        return $api.post("/ucard/api/card/types", { ...params });
    },
    // 商户用户分页列表
    merchantList(params: MerchantParams = { page: { current: 1, row: 10 } }): Promise<BaseResponse<PageResponse<MerchantUser>>> {
        return $api.post("/ucard/api/merchant/user/page", { ...params });
    },
    // 查询商户账户信息
    merchantAccount(params: { merchantId: string }): Promise<BaseResponse<MerchantAccount>> {
        return $api.post("/ucard/api/merchant/account", { ...params });
    },
    // 商户注册选择用户列表
    merchantSearch(params: { keyword: string }): Promise<BaseResponse<MerchantUser[]>> {
        return $api.post("/custom/search/ucard", { ...params });
    },
    // 商户用户注册
    merchantRegister(params: Partial<MerchantUser>): Promise<BaseResponse> {
        return $api.post("/ucard/api/merchant/user/register", { ...params });
    },
    // 更新商户用户信息
    merchantUpdate(params: Partial<MerchantUser>): Promise<BaseResponse> {
        return $api.post("/ucard/api/merchant/user/update", { ...params });
    },
    // 上传KYC附件
    kycUpload(params: FormData): Promise<BaseResponse<{ url: string }>> {
        return $api.post("/ucard/api/merchant/kyc/upload", { ...params });
    },
    // 提交KYC认证
    kycSubmit(params: KycParams): Promise<BaseResponse> {
        return $api.post("/ucard/api/merchant/kyc/submit", { ...params });
    },
    // 查询KYC认证状态
    kycStatus(params: { merchantId: string }): Promise<BaseResponse<KycInfo>> {
        return $api.post("/ucard/api/merchant/kyc/status", { ...params });
    },
    // 获取卡片申请列表
    applyList(params: PageParams): Promise<BaseResponse<PageResponse<PageParams>>> {
        return $api.post("/ucard/api/card/apply/page", { ...params });
    },
    // 获取卡片列表
    cardList(params: PageParams): Promise<BaseResponse<PageResponse<PageParams>>> {
        return $api.post("/ucard/api/card/list", { ...params });
    },
    // 充值记录分页查询
    rechargeList(params: TransactionParams): Promise<BaseResponse<PageResponse<TransactionInfo>>> {
        return $api.post("/ucard/api/card/recharge/page", { ...params });
    },
    // 查询交易记录分页列表
    transactionsList(params: TransactionParams): Promise<BaseResponse<PageResponse<TransactionInfo>>> {
        return $api.post("/ucard/api/card/transac/page", { ...params });
    },
    // 用户订单分页查询
    transferList(params: TransactionParams): Promise<BaseResponse<PageResponse<TransferInfo>>> {
        return $api.post("/ucard/api/transfer/page", { ...params });
    },
    // 文件上传
    ucardUpload(params: FormData): Promise<BaseResponse<{ url: string }>> {
        return $api.post("/ucard/api/upload/file", { ...params });
    },
    // 申请开卡
    ucardApply(params: CardApplyParams): Promise<BaseResponse> {
        return $api.post("/ucard/api/card/apply", { ...params });
    },
    // kyc列表
    kycList(params: PageParams): Promise<BaseResponse<PageResponse<KycInfo>>> {
        return $api.post("/ucard/api/merchant/kyc/page", { ...params });
    },
    // 获取kyc卡片类型列表
    cardKycTypesList(params: PageParams): Promise<BaseResponse<PageResponse<CardType>>> {
        return $api.post("/ucard/api/card/types/list", { ...params });
    },
    // 查询开卡进度
    ucardApplyProgress(params: { applyId: string }): Promise<BaseResponse<{ status: number; message: string }>> {
        return $api.post("/ucard/api/card/apply/progress", { ...params });
    },
    // 银行卡激活
    ucardActivate(params: { cardNo: string; uniqueId: string, password:string }): Promise<BaseResponse> {
        return $api.post("/ucard/api/card/activate", { ...params });
    },
    // 查询充值预估到账金额
    ucardRechargeEstimate(params: { amount: number; currency: string }): Promise<BaseResponse<{ estimatedAmount: number }>> {
        return $api.post("/ucard/api/card/recharge/estimate", { ...params });
    },
    // 银行卡充值
    ucardRecharge(params: { cardNo: string; amount: number; currency: string,uniqueId:string }): Promise<BaseResponse> {
        return $api.post("/ucard/api/card/recharge", { ...params });
    },
    // 查询充值订单
    ucardRechargeOrder(params: { orderNo: string }): Promise<BaseResponse<TransactionInfo>> {
        return $api.post("/ucard/api/card/recharge/order", { ...params });
    },
    // 查询卡片余额
    ucardBalance(params: { cardNo: string; uniqueId: string }): Promise<BaseResponse<{ balance: number; currency: string }>> {
        return $api.post("/ucard/api/card/balance", { ...params });
    },
    // 找回密码
    ucardResetPassword(params: { cardNo: string; newPassword: string }): Promise<BaseResponse> {
        return $api.post("/ucard/api/card/password/reset", { ...params });
    },
    // 冻结卡片
    ucardFreeze(params: { cardNo: string; uniqueId: string }): Promise<BaseResponse> {
        return $api.post("/ucard/api/card/freeze", { ...params });
    },
    // 解冻卡片
    ucardUnfreeze(params: { cardNo: string; uniqueId: string }): Promise<BaseResponse> {
        return $api.post("/ucard/api/card/unfreeze", { ...params });
    },
    // 查询速汇银行及相关配置
    ucardBanks(params: {}): Promise<BaseResponse<Array<{ bankCode: string; bankName: string }>>> {
        return $api.post("/ucard/api/transfer/banks", { ...params });
    },
    // 查询法币汇率
    ucardRate(params: { targetCurrency: string; currency: string; targetCountry:string }): Promise<BaseResponse<RateInfo>> {
        return $api.post("/ucard/api/transfer/rate", { ...params });
    },
    // 代付校验
    ucardValidate(params: ucardValidateParams): Promise<BaseResponse<{ valid: boolean; message: string }>> {
        return $api.post("/ucard/api/transfer/validate", { ...params });
    },
    // 代付付款人校验
    ucardValidatePayer(params: ucardValidateParams): Promise<BaseResponse<{ valid: boolean; message: string }>> {
        return $api.post("/ucard/api/transfer/validate/payer", { ...params });
    },
    // 代付收款人校验
    ucardValidatePayee(params: ucardValidateParams): Promise<BaseResponse<{ valid: boolean; message: string }>> {
        return $api.post("/ucard/api/transfer/validate/payee", { ...params });
    },
    // 代付
    ucardTransfer(params: ucardValidateParams): Promise<BaseResponse<{ orderId: string }>> {
        return $api.post("/ucard/api/transfer", { ...params });
    },
    // 提交调单信息或文件
    ucardDispute(params: { orderId: string; reason: string; files?: FormData }): Promise<BaseResponse> {
        return $api.post("/ucard/api/transfer/dispute", { ...params });
    },
    // 查询订单结果
    ucardResult(params: { orderId: string }): Promise<BaseResponse<{ status: number; message: string }>> {
        return $api.post("/ucard/api/transfer/order/result", { ...params });
    },
    // 国家城市
    ucardCountryCity(params: { code?: string }): Promise<BaseResponse<CountryCityInfo[]>> {
        return $api.post("/ucard/api/card/country", { ...params });
    },
    // 手机区号获取
    countryGet(): Promise<BaseResponse<Array<{ code: string; name: string,enName:string,callingCode:string }>>> {
        return $api.post("/country/get",{});
    },
    // 获取卡片详情
    cardSingle(params: { id: string }): Promise<BaseResponse<CardInfo>> {
        return $api.post("/ucard/api/card/single", { ...params });
    },
    // 获取卡片交易详情
    cardTransacSingle(params: { id: string }): Promise<BaseResponse<TransactionInfo>> {
        return $api.post("/ucard/api/card/transac/single", { ...params });
    },
    ucardOrderDetail: (params: { orderNo: string }) => {
        return $api.get('/api/ucard/order/detail', { params })
    },
    // 速汇转账详情
    ucardTransferSingle(params: { id: string }): Promise<BaseResponse<TransferInfo>> {
        return $api.post('/ucard/api/transfer/single', params)
    },
}
