export type McpTransportType = 'stdio' | 'http';
export type McpAuthType = 'none' | 'bearer' | 'oauth';
export type McpOAuthStatus = 'not_connected' | 'auth_pending' | 'connected' | 'auth_required' | 'error';

export type McpConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error';

/**
 * Confirmation mode for MCP server tool calls:
 * - 'always': Always require confirmation for all tool calls (most restrictive)
 * - 'unsafe_only': Only require confirmation for unsafe operations (balanced)
 * - 'never': Never require confirmation (least restrictive)
 */
export type McpConfirmationMode = 'always' | 'unsafe_only' | 'never';

export interface McpServerInfo {
    id: number;
    name: string;
    description?: string;
    transportType: McpTransportType;
    path: string;
    authType: McpAuthType;
    oauthStatus: McpOAuthStatus;
    apiKey?: string;
    oauthClientId?: string | null;
    oauthClientSecret?: string | null;
    oauthScopes?: string[] | null;
    env?: Record<string, string>;
    confirmationMode: McpConfirmationMode;
    enabled: boolean;
    enabledTools?: string[];  // When null/empty, all tools enabled; otherwise only listed tools
    lastConnectedAt?: string;
    lastError?: string;
    createdAt: string;
    updatedAt: string;
    connectionStatus?: McpConnectionStatus;
}

export interface McpToolInfo {
    name: string;
    namespacedName: string;
    description: string;
    inputSchema: Record<string, unknown>;
}

export interface McpServersResponse {
    servers: McpServerInfo[];
}

export interface McpServerResponse {
    server: McpServerInfo;
}

export interface McpTestConnectionResponse {
    success: boolean;
    toolCount?: number;
    tools?: Array<{
        name: string;
        description: string;
    }>;
    error?: string;
}

export interface McpToolsResponse {
    server: string;
    tools: McpToolInfo[];
}

export interface CreateMcpServerInput {
    name: string;
    description?: string;
    transportType: McpTransportType;
    path: string;
    authType?: McpAuthType;
    apiKey?: string;
    oauthClientId?: string;
    oauthClientSecret?: string;
    oauthScopes?: string[];
    env?: Record<string, string>;
    confirmationMode?: McpConfirmationMode;
    enabled?: boolean;
}

export interface UpdateMcpServerInput {
    description?: string;
    transportType?: McpTransportType;
    path?: string;
    authType?: McpAuthType;
    apiKey?: string;
    oauthClientId?: string;
    oauthClientSecret?: string;
    oauthScopes?: string[];
    env?: Record<string, string>;
    confirmationMode?: McpConfirmationMode;
    enabled?: boolean;
    enabledTools?: string[];
}
