"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.CoreEventWebhooksMcpTools = void 0;
const common_1 = require("@nestjs/common");
const event_webhook_service_1 = require("../../webhook-integration/event-webhook.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreEventWebhooksMcpTools = class CoreEventWebhooksMcpTools {
    constructor(eventWebhookService) {
        this.eventWebhookService = eventWebhookService;
    }
    async listEventWebhooks(args, _context) {
        var _a, _b, _c, _d, _e;
        return this.eventWebhookService.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 getEventWebhook(args, _context) {
        return this.eventWebhookService.get(args.id);
    }
    async createEventWebhook(args, _context) {
        return this.eventWebhookService.create(args);
    }
    async updateEventWebhook(args, _context) {
        const { id } = args, data = __rest(args, ["id"]);
        return this.eventWebhookService.update(id, data);
    }
    async deleteEventWebhooks(args, _context) {
        return this.eventWebhookService.delete({ ids: args.ids });
    }
    async listEventWebhookLogs(args, _context) {
        var _a, _b;
        return this.eventWebhookService.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.CoreEventWebhooksMcpTools = CoreEventWebhooksMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.event-webhooks.list',
        description: 'Lists event-driven webhooks 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)
], CoreEventWebhooksMcpTools.prototype, "listEventWebhooks", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.event-webhooks.get',
        description: 'Returns a single event webhook by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                id: { type: 'number', description: 'Event webhook ID' },
            },
            required: ['id'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreEventWebhooksMcpTools.prototype, "getEventWebhook", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.event-webhooks.create',
        description: 'Creates a new event webhook. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                name: { type: 'string', description: 'Webhook name' },
                slug: { type: 'string', description: 'Webhook slug' },
                url: { type: 'string', description: 'Target URL to POST events to' },
                method: { type: 'string', description: 'HTTP method (default: POST)' },
                status: { type: 'string', description: 'Status (active, inactive)' },
                events: { type: 'array', items: { type: 'string' }, description: 'Event slugs to subscribe to' },
            },
            required: ['name', 'url'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreEventWebhooksMcpTools.prototype, "createEventWebhook", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.event-webhooks.update',
        description: 'Updates an existing event webhook by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                id: { type: 'number', description: 'Event webhook ID' },
                name: { type: 'string', description: 'New name' },
                url: { type: 'string', description: 'New target URL' },
                status: { type: 'string', description: 'New status (active, inactive)' },
                events: { type: 'array', items: { type: 'string' }, description: 'New event slugs to subscribe to' },
            },
            required: ['id'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreEventWebhooksMcpTools.prototype, "updateEventWebhook", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.event-webhooks.delete',
        description: 'Deletes one or more event webhooks by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'Event webhook IDs to delete' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreEventWebhooksMcpTools.prototype, "deleteEventWebhooks", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.event-webhooks.logs.list',
        description: 'Lists delivery logs for an event webhook. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                webhookId: { type: 'number', description: 'Event 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)
], CoreEventWebhooksMcpTools.prototype, "listEventWebhookLogs", null);
exports.CoreEventWebhooksMcpTools = CoreEventWebhooksMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [event_webhook_service_1.EventWebhookService])
], CoreEventWebhooksMcpTools);
//# sourceMappingURL=core-event-webhooks.mcp-tools.js.map