import type { ArtifactListItem } from "@/api";

export type ArtifactCategory = "chart" | "image" | "other";

/**
 * 推断 artifact 分类
 * 
 * 后端 OpenAPI 已经返回规范化的类型值：'chart', 'image', 'other'
 * 这个函数主要是类型转换和空值处理
 */
export const inferArtifactCategory = (
  tag: ArtifactListItem | undefined,
): ArtifactCategory => {
  if (!tag) {
    return "other";
  }

  if (!tag.type) {
    return "other";
  }

  // 后端已经返回规范化的值：'chart', 'image', 'other'
  return tag.type as ArtifactCategory;
};

export const inferArtifactCategoryFromValues = (
  rawType?: string | null,
): ArtifactCategory => {
  if (!rawType) return "other";
  
  const typeValue = rawType.toLowerCase().trim();
  
  // 后端返回规范化的值
  if (typeValue === "chart" || typeValue === "image" || typeValue === "other") {
    return typeValue as ArtifactCategory;
  }
  
  return "other";
};

