import { creativeApi, type CreativeOptions, type ModelConfig } from "@/api/creative";

export async function ensureScriptAnalysisTextModel(
  options: CreativeOptions,
  configs: ModelConfig[],
): Promise<ModelConfig[]> {
  if (configs.some((config) => config.model_type === "text" && Boolean(config.model_id))) return configs;
  const defaultModel = options.models.find((model) => model.model_type === "text");
  if (!defaultModel) return configs;
  await creativeApi.saveUserModelConfig("script_analysis", "text", defaultModel.id);
  return creativeApi.userModelConfigs("script_analysis");
}
