import type { Doc } from './_generated/dataModel';

export type AgentRuntimeName = 'codex' | 'opencode' | 'claude';

// Which runtimes a provider profile can drive.
export const runtimesForProfile = (
  profile: Pick<Doc<'aiProviderProfiles'>, 'provider' | 'authType'>,
): AgentRuntimeName[] => {
  if (
    profile.provider === 'opencode_openai_login' ||
    profile.authType === 'opencode_auth_json'
  ) {
    return ['codex']; // ChatGPT-login snapshot → Codex CLI only
  }
  if (profile.provider === 'anthropic') {
    return profile.authType === 'anthropic_oauth_json'
      ? ['claude']
      : ['claude', 'opencode'];
  }
  if (profile.provider === 'openai') return ['opencode', 'codex'];
  // Every remaining API-key provider is OpenAI-compatible → OpenCode.
  return ['opencode'];
};
