import request from '@/utils/request';
import type { ApiResult } from '@/api';
import {APP_API_URL} from '@/config/setting';

/**
 * 实人认证结果
 */
export interface IdVerifyResult {
  isMatch: boolean;
  message: string;
}

/**
 * 身份证二要素核验（阿里云实人认证）
 * 校验姓名和身份证号是否一致
 */
export async function verifyIdCard(realName: string, idCard: string) {
  const res = await request.post<ApiResult<IdVerifyResult>>(
      APP_API_URL + '/id-verification/verify-id-card',
    null,
    {
      params: { realName, idCard }
    }
  );
  if (res.data.code === 200 || res.data.code === 0) {
    return res.data.data as IdVerifyResult;
  }
  return Promise.reject(new Error(res.data.message || '核验失败'));
}
