"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 __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoreWebhooksMcpTools = void 0;
const common_1 = require("@nestjs/common");
const webhook_integration_service_1 = require("../../webhook-integration/webhook-integration.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreWebhooksMcpTools = class CoreWebhooksMcpTools {
    constructor(webhookService) {
        this.webhookService = webhookService;
    }
    async listWebhooks(args, _context) {
        var _a, _b, _c, _d, _e;
        return this.webhookService.list({
            page: (_a = args.page) !== null && _a !== void 0 ? _a : 1,
            pageSize: (_b = args.pageSize) !== null && _b !== void 0 ? _b : 20,
            search: (_c = args.search) !== null && _c !== void 0 ? _c : '',
            sortField: (_d = args.sortField) !== null && _d !== void 0 ? _d : 'id',
            sortOrder: (_e = args.sortOrder) !== null && _e !== void 0 ? _e : 'asc',
            fields: '',
        });
    }
    async getWebhook(args, _context) {
        return this.webhookService.get(args.id);
    }
    async createWebhook(args, _context) {
        return this.webhookService.create(args);
    }
    async updateWebhook(args, _context) {
        const { id } = args, data = __rest(args, ["id"]);
        return this.webhookService.update(id, data);
    }
    async deleteWebhooks(args, _context) {
        return this.webhookService.delete({ ids: args.ids });
    }
    async listWebhookActions(args, _context) {
        return this.webhookService.listActions(args.webhookId);
    }
    async createWebhookAction(args, _context) {
        const { webhookId } = args, data = __rest(args, ["webhookId"]);
        return this.webhookService.createAction(webhookId, data);
    }
    async updateWebhookAction(args, _context) {
        const { webhookId, actionId } = args, data = __rest(args, ["webhookId", "actionId"]);
        return this.webhookService.updateAction(webhookId, actionId, data);
    }
    async deleteWebhookActions(args, _context) {
        return this.webhookService.deleteActions(args.webhookId, { ids: args.ids });
    }
    async listWebhookLogs(args, _context) {
        var _a, _b;
        return this.webhookService.listLogs(args.webhookId, {
            page: (_a = args.page) !== null && _a !== void 0 ? _a : 1,
            pageSize: (_b = args.pageSize) !== null && _b !== void 0 ? _b : 20,
            search: '',
            sortField: 'id',
            sortOrder: 'desc',
            fields: '',
        });
    }
};
exports.CoreWebhooksMcpTools = CoreWebhooksMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.list',
        description: 'Lists webhook integrations with optional pagination. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
                search: { type: 'string', description: 'Search term' },
                sortField: { type: 'string', description: 'Field to sort by' },
                sortOrder: { type: 'string', enum: ['asc', 'desc'], description: 'Sort direction' },
            },
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "listWebhooks", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.get',
        description: 'Returns a single webhook integration by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                id: { type: 'number', description: 'Webhook ID' },
            },
            required: ['id'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "getWebhook", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.create',
        description: 'Creates a new webhook integration. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                name: { type: 'string', description: 'Webhook name' },
                slug: { type: 'string', description: 'Webhook slug' },
                description: { type: 'string', description: 'Webhook description' },
            },
            required: ['name'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "createWebhook", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.update',
        description: 'Updates an existing webhook integration by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                id: { type: 'number', description: 'Webhook ID' },
                name: { type: 'string', description: 'New name' },
                slug: { type: 'string', description: 'New slug' },
                description: { type: 'string', description: 'New description' },
            },
            required: ['id'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "updateWebhook", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.delete',
        description: 'Deletes one or more webhook integrations by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'Webhook IDs to delete' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "deleteWebhooks", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.actions.list',
        description: 'Lists actions configured for a webhook. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                webhookId: { type: 'number', description: 'Webhook ID' },
            },
            required: ['webhookId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "listWebhookActions", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.actions.create',
        description: 'Creates a new action for a webhook. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                webhookId: { type: 'number', description: 'Webhook ID' },
                type: { type: 'string', description: 'Action type (e.g. email, http)' },
                config: { type: 'object', description: 'Action configuration' },
            },
            required: ['webhookId', 'type'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "createWebhookAction", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.actions.update',
        description: 'Updates an existing webhook action. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                webhookId: { type: 'number', description: 'Webhook ID' },
                actionId: { type: 'number', description: 'Action ID' },
                type: { type: 'string', description: 'New action type' },
                config: { type: 'object', description: 'New action configuration' },
            },
            required: ['webhookId', 'actionId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "updateWebhookAction", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.actions.delete',
        description: 'Deletes one or more webhook actions. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                webhookId: { type: 'number', description: 'Webhook ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'Action IDs to delete' },
            },
            required: ['webhookId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "deleteWebhookActions", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.webhooks.logs.list',
        description: 'Lists execution logs for a webhook. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                webhookId: { type: 'number', description: 'Webhook ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
            },
            required: ['webhookId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreWebhooksMcpTools.prototype, "listWebhookLogs", null);
exports.CoreWebhooksMcpTools = CoreWebhooksMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [webhook_integration_service_1.WebhookIntegrationService])
], CoreWebhooksMcpTools);
//# sourceMappingURL=core-webhooks.mcp-tools.js.map