import { LAYOUT_EDITOR_CHAT_TYPE_ID, LAYOUT_EDITOR_GUIDED_CHAT_TYPE_ID } from '../../app/main/chatTypeDefaults';

type LayoutCodexChatType = {
  id: string;
  name: string;
  description: string;
};

const PRIORITIZED_CHAT_TYPE_IDS = [
  LAYOUT_EDITOR_GUIDED_CHAT_TYPE_ID,
  LAYOUT_EDITOR_CHAT_TYPE_ID,
  'general-request',
  'api-request-template',
] as const;

export function resolvePreferredLayoutCodexChatType(chatTypes: LayoutCodexChatType[]) {
  for (const id of PRIORITIZED_CHAT_TYPE_IDS) {
    const matched = chatTypes.find((item) => item.id === id);
    if (matched) {
      return matched;
    }
  }

  return chatTypes.find((item) => item.id !== 'general-inquiry') ?? chatTypes[0] ?? null;
}
