export type AIProvider = "mindavio_core" | "openai" | "anthropic";

export interface AISettingsRecord {
  user_id: string;
  provider: AIProvider;
  model: string;
  openai_encrypted_api_key: string | null;
  openai_api_key_hint: string | null;
  anthropic_encrypted_api_key: string | null;
  anthropic_api_key_hint: string | null;
  custom_instructions: string;
}

export interface AISettingsPublic {
  provider: AIProvider;
  model: string;
  openaiConnected: boolean;
  openaiApiKeyHint: string | null;
  anthropicConnected: boolean;
  anthropicApiKeyHint: string | null;
  customInstructions: string;
}

export interface ConversationMessage {
  role: "user" | "assistant";
  content: string;
}

export interface AIWorkspaceContext {
  activeTeamId?: string | null;
}

export interface AIWorkspaceMemoryRecord {
  id: string;
  user_id: string | null;
  team_id: string | null;
  memory: string;
  source: string;
  created_at: string;
  updated_at: string;
}

export interface ToolDefinition {
  name: string;
  description: string;
  input_schema: {
    type: "object";
    properties: Record<string, unknown>;
    required?: string[];
    additionalProperties?: boolean;
  };
}

export interface ToolCall {
  id: string;
  name: string;
  arguments: Record<string, unknown>;
}

export interface ProviderGenerateParams {
  apiKey: string;
  model: string;
  systemPrompt: string;
  messages: ConversationMessage[];
  tools: ToolDefinition[];
  toolResults?: Array<{
    callId: string;
    output: Record<string, unknown>;
  }>;
  providerState?: string;
}

export interface ProviderGenerateResult {
  text: string;
  toolCalls: ToolCall[];
  providerState?: string;
}
