import {
  buildChatSkillPrompt,
  CHAT_SKILL_DEFINITIONS,
  filterChatSkills as filterChatSkillDefinitions,
} from '../../chat-skills.mjs';
import { buildPublishSkillPrompt, PUBLISH_SKILL_NAME } from './publishSkill';

export type ChatSkillIconId =
  | 'spark'
  | 'page'
  | 'search'
  | 'web'
  | 'form'
  | 'table'
  | 'summary'
  | 'analyze';

export type ChatSkillOption = {
  id: string;
  label: string;
  icon: ChatSkillIconId;
  skillName?: string;
  buildPrompt: (skillName?: string) => string;
  requiresPublish?: boolean;
  requiresSkill?: string;
  prefillOnly?: boolean;
};

export const CHAT_SKILL_OPTIONS: ChatSkillOption[] = CHAT_SKILL_DEFINITIONS.map((def) => ({
  id: def.id,
  label: def.label,
  icon: def.icon,
  skillName: def.skillName,
  requiresPublish: def.requiresPublish,
  requiresSkill: def.requiresSkill,
  prefillOnly: def.prefillOnly,
  buildPrompt: (skillName) => buildChatSkillPrompt(def.promptKey, skillName ?? def.skillName),
}));

export function filterChatSkills(
  options: ChatSkillOption[],
  ctx: { grantedSkills?: string[]; canPublish: boolean },
): ChatSkillOption[] {
  return filterChatSkillDefinitions(options, ctx);
}

export { buildPublishSkillPrompt, PUBLISH_SKILL_NAME };
