// *****************************************************************************
// Copyright (C) 2025 EclipseSource GmbH.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { nls, PreferenceSchema } from '@theia/core';
import {
    NOTIFICATION_TYPES
} from './notification-types';

export const AGENT_SETTINGS_PREF = 'ai-features.agentSettings';

export const AgentSettingsPreferenceSchema: PreferenceSchema = {
    properties: {
        [AGENT_SETTINGS_PREF]: {
            type: 'object',
            title: nls.localize('theia/ai/agents/title', 'Agent Settings'),
            hidden: true,
            markdownDescription: nls.localize('theia/ai/agents/mdDescription', 'Configure agent settings such as enabling or disabling specific agents, configuring prompts and \
        selecting LLMs.'),
            additionalProperties: {
                type: 'object',
                properties: {
                    enable: {
                        type: 'boolean',
                        title: nls.localize('theia/ai/agents/enable/title', 'Enable Agent'),
                        markdownDescription: nls.localize('theia/ai/agents/enable/mdDescription', 'Specifies whether the agent should be enabled (true) or disabled (false).'),
                        default: true
                    },
                    showInChat: {
                        type: 'boolean',
                        title: nls.localize('theia/ai/agents/showInChat/title', 'Show in Chat'),
                        markdownDescription: nls.localize('theia/ai/agents/showInChat/mdDescription',
                            'Specifies whether the agent should be shown in the chat UI (true) or hidden (false).'),
                        default: true
                    },
                    languageModelRequirements: {
                        type: 'array',
                        title: nls.localize('theia/ai/agents/languageModelRequirements/title', 'Language Model Requirements'),
                        markdownDescription: nls.localize('theia/ai/agents/languageModelRequirements/mdDescription', 'Specifies the used language models for this agent.'),
                        items: {
                            type: 'object',
                            properties: {
                                purpose: {
                                    type: 'string',
                                    title: nls.localize('theia/ai/agents/languageModelRequirements/purpose/title', 'Purpose'),
                                    markdownDescription: nls.localize('theia/ai/agents/languageModelRequirements/purpose/mdDescription',
                                        'The purpose for which this language model is used.')
                                },
                                identifier: {
                                    type: 'string',
                                    title: nls.localizeByDefault('Identifier'),
                                    markdownDescription: nls.localize('theia/ai/agents/languageModelRequirements/identifier/mdDescription',
                                        'The identifier of the language model to be used.')
                                }
                            },
                            required: ['purpose', 'identifier']
                        }
                    },
                    selectedVariants: {
                        type: 'object',
                        title: nls.localize('theia/ai/agents/selectedVariants/title', 'Selected Variants'),
                        markdownDescription: nls.localize('theia/ai/agents/selectedVariants/mdDescription', 'Specifies the currently selected prompt variants for this agent.'),
                        additionalProperties: {
                            type: 'string'
                        }
                    },
                    completionNotification: {
                        type: 'string',
                        enum: [...NOTIFICATION_TYPES],
                        title: nls.localize('theia/ai/agents/completionNotification/title', 'Notification'),
                        markdownDescription: nls.localize('theia/ai/agents/completionNotification/mdDescription',
                            'Notification behavior when this agent needs your attention, i.e. it completed a task or requests your input. \
                    If not set, the global default notification setting will be used.\n\
                    - `os-notification`: Show OS/system notifications\n\
                    - `message`: Show notifications in the status bar/message area\n\
                    - `blink`: Blink or highlight the UI\n\
                    - `off`: Disable notifications for this agent')
                    },
                    capabilityOverrides: {
                        type: 'object',
                        title: nls.localize('theia/ai/agents/capabilityOverrides/title', 'Capability Overrides'),
                        markdownDescription: nls.localize('theia/ai/agents/capabilityOverrides/mdDescription',
                            'User overrides for template-based capabilities. Keys are capability fragment IDs, values are enabled (true) or disabled (false).'),
                        additionalProperties: {
                            type: 'boolean'
                        }
                    },
                    genericCapabilitySelections: {
                        type: 'object',
                        title: nls.localize('theia/ai/agents/genericCapabilitySelections/title', 'Generic Capability Selections'),
                        markdownDescription: nls.localize('theia/ai/agents/genericCapabilitySelections/mdDescription',
                            'User selections for generic capabilities such as skills, functions, and MCP tools.'),
                        properties: {
                            skills: {
                                type: 'array',
                                items: { type: 'string' },
                                description: nls.localize('theia/ai/agents/genericCapabilitySelections/skills', 'Selected skill IDs')
                            },
                            mcpFunctions: {
                                type: 'array',
                                items: { type: 'string' },
                                description: nls.localize('theia/ai/agents/genericCapabilitySelections/mcpFunctions', 'Selected MCP function IDs')
                            },
                            functions: {
                                type: 'array',
                                items: { type: 'string' },
                                description: nls.localize('theia/ai/agents/genericCapabilitySelections/functions', 'Selected function IDs')
                            },
                            promptFragments: {
                                type: 'array',
                                items: { type: 'string' },
                                description: nls.localize('theia/ai/agents/genericCapabilitySelections/promptFragments', 'Selected prompt fragment IDs')
                            },
                            agentDelegation: {
                                type: 'array',
                                items: { type: 'string' },
                                description: nls.localize('theia/ai/agents/genericCapabilitySelections/agentDelegation', 'Selected agent IDs for delegation')
                            },
                            variables: {
                                type: 'array',
                                items: { type: 'string' },
                                description: nls.localize('theia/ai/agents/genericCapabilitySelections/variables', 'Selected variable names')
                            }
                        }
                    },
                    serverToolSelections: {
                        type: 'object',
                        title: nls.localize('theia/ai/agents/serverToolSelections/title', 'Server Tool Selections'),
                        markdownDescription: nls.localize('theia/ai/agents/serverToolSelections/mdDescription',
                            'User selections for provider server tools, keyed by model vendor. Each value holds the enabled server tool ids for that vendor.'),
                        additionalProperties: {
                            type: 'array',
                            items: { type: 'string' }
                        }
                    }
                },
                required: ['languageModelRequirements']
            }
        }
    }
};
