export type RecommendationTaskStatus =
  | "pending"
  | "processing"
  | "completed"
  | "failed";

export interface RecommendationTaskInitResponse {
  task_id: string;
  status: RecommendationTaskStatus;
}

export interface RecommendationTaskProgress {
  message?: string;
}

export interface RecommendationTaskStatusResponse<T> {
  task_id: string;
  status: RecommendationTaskStatus;
  progress?: RecommendationTaskProgress;
  result?: T;
  error?: string;
}

export const normalizeRecommendationTaskStatus = (
  status?: string,
): RecommendationTaskStatus => {
  switch (status?.toLowerCase()) {
    case "started":
    case "processing":
      return "processing";
    case "success":
    case "completed":
      return "completed";
    case "failure":
    case "failed":
      return "failed";
    default:
      return "pending";
  }
};

export const isRecommendationTaskRunning = (status: RecommendationTaskStatus) =>
  status === "pending" || status === "processing";
