/**
 * Typed convenience wrapper for the mcpctl `llm` resource. Compiles down to a
 * generic {@link McpctlResource} with `kind: "llm"`. Field types mirror mcpd's
 * CreateLlmSchema / UpdateLlmSchema (src/mcpd/src/validation/llm.schema.ts).
 *
 *   new mcpctl.Llm("homelab-qwen", {
 *     name: "qwen3-thinking",
 *     type: "openai",
 *     model: servedModelName,        // pulumi.Input<string>
 *     url: litellmUrl,
 *     tier: "heavy",
 *     mcpd: { url, token: cfg.requireSecret("mcpdPat") },
 *   });
 */
import type { Input, CustomResourceOptions } from '@pulumi/pulumi';
import { McpctlResource, McpdConnInput } from './resource';

export const LLM_TYPES = ['anthropic', 'openai', 'deepseek', 'vllm', 'ollama', 'gemini-cli'] as const;
export type LlmType = (typeof LLM_TYPES)[number];

export const LLM_TIERS = ['fast', 'heavy'] as const;
export type LlmTier = (typeof LLM_TIERS)[number];

/** Reference to a key inside a Secret; mcpd resolves it server-side. */
export interface LlmApiKeyRef {
  name: Input<string>;
  key: Input<string>;
}

export interface LlmArgs {
  /** llm resource name (upsert key). Immutable — changing it replaces. */
  name: Input<string>;
  /** Provider type. Immutable — changing it replaces. */
  type: Input<LlmType>;
  model: Input<string>;
  /** Endpoint URL; omit for the provider default. */
  url?: Input<string>;
  tier?: Input<LlmTier>;
  description?: Input<string>;
  apiKeyRef?: Input<LlmApiKeyRef>;
  poolName?: Input<string>;
  extraConfig?: Input<Record<string, unknown>>;
  mcpd: Input<McpdConnInput>;
}

export class Llm extends McpctlResource {
  constructor(name: string, args: LlmArgs, opts?: CustomResourceOptions) {
    const { name: llmName, mcpd, ...spec } = args;
    super(name, { kind: 'llm', name: llmName, spec: spec as Record<string, unknown>, mcpd }, opts);
  }
}
