import type { ModelVerificationData } from '#/api/ai/llm';

export type VerifyButtonStatus =
  | 'error'
  | 'idle'
  | 'loading'
  | 'success'
  | 'warning';

export interface ModelVerificationFeedback {
  dimension?: number;
  message: string;
  status: 'error' | 'success' | 'warning';
}

interface ModelVerificationResponse {
  data?: ModelVerificationData;
  errorCode: number;
  message?: string;
}

export function resolveModelVerificationFeedback(
  response: ModelVerificationResponse,
  _modelType: string,
): ModelVerificationFeedback {
  if (response.errorCode !== 0) {
    return {
      message: response.message || '验证失败',
      status: 'error',
    };
  }

  if (response.data?.status === 'FAILED') {
    return {
      message: response.data.message || '验证失败',
      status: 'error',
    };
  }

  const dimension = response.data?.dimension;
  return {
    dimension,
    message: '验证通过',
    status: 'success',
  };
}

export function getVerifyButtonText(status: VerifyButtonStatus): string {
  if (status === 'loading') {
    return '验证中';
  }
  if (status === 'success') {
    return '验证通过';
  }
  if (status === 'warning') {
    return '验证通过';
  }
  if (status === 'error') {
    return '验证失败';
  }
  return '验证配置';
}
