"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SystemPromptsController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const system_prompts_service_1 = require("./system-prompts.service");
const system_prompt_dto_1 = require("./dto/system-prompt.dto");
const set_enabled_tools_dto_1 = require("./dto/set-enabled-tools.dto");
const toggle_tool_dto_1 = require("./dto/toggle-tool.dto");
const set_enabled_mcp_tools_dto_1 = require("./dto/set-enabled-mcp-tools.dto");
const toggle_mcp_tool_dto_1 = require("./dto/toggle-mcp-tool.dto");
const core_entities_1 = require("../core-entities");
let SystemPromptsController = class SystemPromptsController {
    constructor(systemPromptsService) {
        this.systemPromptsService = systemPromptsService;
    }
    async create(createSystemPromptDto) {
        return this.systemPromptsService.create(createSystemPromptDto);
    }
    async preview(previewDto) {
        return this.systemPromptsService.preview(previewDto);
    }
    async getToolNames() {
        return this.systemPromptsService.getToolNames();
    }
    async getAllToolNames() {
        const tools = this.systemPromptsService.getAllToolNames();
        return { tools };
    }
    async getAllMcpToolNames() {
        const mcpTools = await this.systemPromptsService.getAllMcpToolNames();
        return { mcpTools };
    }
    async findAll() {
        return this.systemPromptsService.findAll();
    }
    async findOne(id) {
        return this.systemPromptsService.findOne(id);
    }
    async findOneRaw(id) {
        return this.systemPromptsService.findOneRaw(id);
    }
    async getEnabledTools(id) {
        const enabledTools = await this.systemPromptsService.getEnabledTools(id);
        return { enabledTools };
    }
    async getToolsForPrompt(id) {
        const tools = await this.systemPromptsService.getToolsForPrompt(id);
        return { tools };
    }
    async setEnabledTools(id, dto) {
        const enabledTools = dto.enabledTools !== undefined
            ? dto.enabledTools
            : dto.enabledToolsArray || 'all';
        const updated = await this.systemPromptsService.setEnabledTools(id, enabledTools);
        return { enabledTools: updated.enabledTools };
    }
    async toggleTool(id, dto) {
        const updated = await this.systemPromptsService.toggleTool(id, dto.toolName);
        return { enabledTools: updated.enabledTools };
    }
    async getEnabledMcpTools(id) {
        const enabledMcpTools = await this.systemPromptsService.getEnabledMcpTools(id);
        return { enabledMcpTools };
    }
    async getMcpToolsForPrompt(id) {
        const mcpTools = await this.systemPromptsService.getMcpToolsForPrompt(id);
        return { mcpTools };
    }
    async setEnabledMcpTools(id, dto) {
        const enabledMcpTools = dto.enabledMcpTools !== undefined
            ? dto.enabledMcpTools
            : dto.enabledMcpToolsArray || 'all';
        const updated = await this.systemPromptsService.setEnabledMcpTools(id, enabledMcpTools);
        return { enabledMcpTools: updated.enabledMcpTools };
    }
    async toggleMcpTool(id, dto) {
        const updated = await this.systemPromptsService.toggleMcpTool(id, dto.mcpToolName);
        return { enabledMcpTools: updated.enabledMcpTools };
    }
    async update(id, updateSystemPromptDto) {
        return this.systemPromptsService.update(id, updateSystemPromptDto);
    }
    async setDefault(id) {
        return this.systemPromptsService.setDefault(id);
    }
    async duplicate(id) {
        return this.systemPromptsService.duplicate(id);
    }
    async remove(id) {
        return this.systemPromptsService.remove(id);
    }
};
exports.SystemPromptsController = SystemPromptsController;
__decorate([
    (0, common_1.Post)(),
    (0, swagger_1.ApiOperation)({ summary: 'Create a new system prompt' }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'System prompt created',
        type: core_entities_1.SystemPrompt,
    }),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [system_prompt_dto_1.CreateSystemPromptDto]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "create", null);
__decorate([
    (0, common_1.Post)('preview'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, swagger_1.ApiOperation)({
        summary: 'Preview rendered system prompt (inject tool definitions)',
    }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Rendered prompt',
        type: system_prompt_dto_1.PreviewSystemPromptResponseDto,
    }),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [system_prompt_dto_1.PreviewSystemPromptDto]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "preview", null);
__decorate([
    (0, common_1.Get)('tools'),
    (0, swagger_1.ApiOperation)({ summary: 'Get names of tools enabled for current session' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'List of enabled tool names' }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "getToolNames", null);
__decorate([
    (0, common_1.Get)('all-tools'),
    (0, swagger_1.ApiOperation)({ summary: 'Get all available tool names' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'List of all tool names' }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "getAllToolNames", null);
__decorate([
    (0, common_1.Get)('all-mcp-tools'),
    (0, swagger_1.ApiOperation)({
        summary: 'Get all available MCP tool names (serverName__toolName format)',
    }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'List of available MCP tool names' }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "getAllMcpToolNames", null);
__decorate([
    (0, common_1.Get)(),
    (0, swagger_1.ApiOperation)({ summary: 'List all system prompts' }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'List of system prompts',
        type: [core_entities_1.SystemPrompt],
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "findAll", null);
__decorate([
    (0, common_1.Get)(':id'),
    (0, swagger_1.ApiOperation)({ summary: 'Get a system prompt by ID' }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'System prompt found',
        type: core_entities_1.SystemPrompt,
    }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'System prompt not found' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "findOne", null);
__decorate([
    (0, common_1.Get)(':id/raw'),
    (0, swagger_1.ApiOperation)({ summary: 'Get raw system prompt content (unrendered)' }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Raw system prompt',
        type: core_entities_1.SystemPrompt,
    }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'System prompt not found' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "findOneRaw", null);
__decorate([
    (0, common_1.Get)(':id/enabled-tools'),
    (0, swagger_1.ApiOperation)({ summary: 'Get enabled tools for a system prompt' }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Enabled tools list or "all"' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "getEnabledTools", null);
__decorate([
    (0, common_1.Get)(':id/tools-for-prompt'),
    (0, swagger_1.ApiOperation)({
        summary: 'Get tool definitions formatted for prompt injection',
    }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Tool definitions for prompt' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "getToolsForPrompt", null);
__decorate([
    (0, common_1.Patch)(':id/enabled-tools'),
    (0, swagger_1.ApiOperation)({ summary: 'Set enabled tools for a system prompt' }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Enabled tools updated' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, set_enabled_tools_dto_1.SetEnabledToolsDto]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "setEnabledTools", null);
__decorate([
    (0, common_1.Patch)(':id/toggle-tool'),
    (0, swagger_1.ApiOperation)({ summary: 'Toggle a single tool on/off' }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Tool toggled' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, toggle_tool_dto_1.ToggleToolDto]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "toggleTool", null);
__decorate([
    (0, common_1.Get)(':id/enabled-mcp-tools'),
    (0, swagger_1.ApiOperation)({
        summary: 'Get enabled MCP tools for a system prompt',
    }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Enabled MCP tools list or "all"' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "getEnabledMcpTools", null);
__decorate([
    (0, common_1.Get)(':id/mcp-tools-for-prompt'),
    (0, swagger_1.ApiOperation)({
        summary: 'Get MCP tool names that should be sent to LLM for a system prompt (considers both global and prompt-level settings)',
    }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Resolved MCP tool names' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "getMcpToolsForPrompt", null);
__decorate([
    (0, common_1.Patch)(':id/enabled-mcp-tools'),
    (0, swagger_1.ApiOperation)({ summary: 'Set enabled MCP tools for a system prompt' }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'Enabled MCP tools updated' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, set_enabled_mcp_tools_dto_1.SetEnabledMcpToolsDto]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "setEnabledMcpTools", null);
__decorate([
    (0, common_1.Patch)(':id/toggle-mcp-tool'),
    (0, swagger_1.ApiOperation)({
        summary: 'Toggle a single MCP tool on/off for a system prompt',
    }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: 'MCP tool toggled' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, toggle_mcp_tool_dto_1.ToggleMcpToolDto]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "toggleMcpTool", null);
__decorate([
    (0, common_1.Put)(':id'),
    (0, swagger_1.ApiOperation)({ summary: 'Update a system prompt' }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'System prompt updated',
        type: core_entities_1.SystemPrompt,
    }),
    (0, swagger_1.ApiResponse)({ status: 403, description: 'Cannot modify built-in prompt' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'System prompt not found' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, system_prompt_dto_1.UpdateSystemPromptDto]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "update", null);
__decorate([
    (0, common_1.Post)(':id/set-default'),
    (0, common_1.HttpCode)(common_1.HttpStatus.OK),
    (0, swagger_1.ApiOperation)({ summary: 'Set this prompt as the default' }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({
        status: 200,
        description: 'Set as default',
        type: core_entities_1.SystemPrompt,
    }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'System prompt not found' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "setDefault", null);
__decorate([
    (0, common_1.Post)(':id/duplicate'),
    (0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
    (0, swagger_1.ApiOperation)({ summary: 'Duplicate a system prompt' }),
    (0, swagger_1.ApiParam)({
        name: 'id',
        description: 'System prompt UUID to duplicate',
        format: 'uuid',
    }),
    (0, swagger_1.ApiResponse)({
        status: 201,
        description: 'System prompt duplicated',
        type: core_entities_1.SystemPrompt,
    }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'System prompt not found' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "duplicate", null);
__decorate([
    (0, common_1.Delete)(':id'),
    (0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
    (0, swagger_1.ApiOperation)({ summary: 'Delete a system prompt' }),
    (0, swagger_1.ApiParam)({ name: 'id', description: 'System prompt UUID', format: 'uuid' }),
    (0, swagger_1.ApiResponse)({ status: 204, description: 'System prompt deleted' }),
    (0, swagger_1.ApiResponse)({ status: 403, description: 'Cannot delete built-in prompt' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: 'System prompt not found' }),
    __param(0, (0, common_1.Param)('id', common_1.ParseUUIDPipe)),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Promise)
], SystemPromptsController.prototype, "remove", null);
exports.SystemPromptsController = SystemPromptsController = __decorate([
    (0, swagger_1.ApiTags)('system-prompts'),
    (0, common_1.Controller)('system-prompts'),
    __metadata("design:paramtypes", [system_prompts_service_1.SystemPromptsService])
], SystemPromptsController);
//# sourceMappingURL=system-prompts.controller.js.map