import { requestClient } from '#/api/request';

const prefix = 'ai-generation/';

export interface ShadowCompareRow {
  id: number;
  store_id: number;
  register_id: number;
  doctor_id: number;
  scene: string;
  prescription_type: number;
  primary_generation_id: number;
  primary_provider: string;
  primary_model: string;
  primary_tokens: number;
  primary_duration_ms: number;
  primary_status: number;
  shadow_generation_id: number;
  shadow_provider: string;
  shadow_model: string;
  shadow_tokens: number;
  shadow_duration_ms: number;
  shadow_status: number;
  content_diff_hash: string;
  content_similarity: number;
  quality_score: number;
  remark: string;
  created_at: number;
}

export interface ShadowListResult {
  list: ShadowCompareRow[];
  total: number;
  page: number;
  size: number;
}

export interface ShadowStats {
  count: number;
  avg_primary_tokens: number;
  avg_shadow_tokens: number;
  avg_primary_duration_ms: number;
  avg_shadow_duration_ms: number;
  primary_success_rate: number;
  shadow_success_rate: number;
  avg_content_similarity: number;
}

export interface ShadowListParams {
  store_id?: number;
  scene?: string;
  primary_provider?: string;
  shadow_provider?: string;
  date_start?: number;
  date_end?: number;
  page?: number;
  size?: number;
}

export async function getShadowList(params: ShadowListParams) {
  return requestClient.get<ShadowListResult>(`${prefix}shadow-list`, { params });
}

export async function getShadowDetail(id: number) {
  return requestClient.get<ShadowCompareRow>(`${prefix}shadow-detail`, { params: { id } });
}

export async function getShadowStats(params: Partial<ShadowListParams>) {
  return requestClient.get<ShadowStats>(`${prefix}shadow-stats`, { params });
}
