"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.CoreRoutesMcpTools = void 0;
const common_1 = require("@nestjs/common");
const api_pagination_1 = require("@hed-hog/api-pagination");
const route_service_1 = require("../../route/route.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreRoutesMcpTools = class CoreRoutesMcpTools {
    constructor(routeService) {
        this.routeService = routeService;
    }
    async listRoutes(args, _context) {
        var _a, _b, _c, _d, _e;
        return this.routeService.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 getRoute(args, context) {
        return this.routeService.get(args.routeId, context.locale);
    }
    async createRoute(args, context) {
        return this.routeService.create(args, context.locale);
    }
    async updateRoute(args, context) {
        const { routeId } = args, data = __rest(args, ["routeId"]);
        return this.routeService.update({ id: routeId, data: data }, context.locale);
    }
    async deleteRoutes(args, context) {
        return this.routeService.delete({ ids: args.ids }, context.locale);
    }
    async listRouteRoles(args, context) {
        var _a, _b;
        return this.routeService.listRoles(context.locale, args.routeId, {
            page: (_a = args.page) !== null && _a !== void 0 ? _a : 1,
            pageSize: (_b = args.pageSize) !== null && _b !== void 0 ? _b : 20,
            search: '',
            sortField: 'id',
            sortOrder: api_pagination_1.PageOrderDirection.Asc,
            fields: '',
        });
    }
    async updateRouteRoles(args, _context) {
        return this.routeService.updateRoles(args.routeId, { ids: args.ids });
    }
    async listRouteScreens(args, context) {
        var _a, _b;
        return this.routeService.listScreens(context.locale, args.routeId, {
            page: (_a = args.page) !== null && _a !== void 0 ? _a : 1,
            pageSize: (_b = args.pageSize) !== null && _b !== void 0 ? _b : 20,
            search: '',
            sortField: 'id',
            sortOrder: api_pagination_1.PageOrderDirection.Asc,
            fields: '',
        });
    }
    async updateRouteScreens(args, _context) {
        return this.routeService.updateScreens(args.routeId, { ids: args.ids });
    }
};
exports.CoreRoutesMcpTools = CoreRoutesMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.routes.list',
        description: 'Lists all routes with optional pagination and search. 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)
], CoreRoutesMcpTools.prototype, "listRoutes", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.routes.get',
        description: 'Returns a single route by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                routeId: { type: 'number', description: 'Route ID' },
            },
            required: ['routeId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRoutesMcpTools.prototype, "getRoute", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.routes.create',
        description: 'Creates a new HTTP or MCP route. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                url: { type: 'string', description: 'Route URL (for HTTP routes)' },
                method: { type: 'string', description: 'HTTP method (GET, POST, PATCH, DELETE, PUT)' },
                type: { type: 'string', enum: ['HTTP', 'MCP'], description: 'Route type (default: HTTP)' },
                tool_name: { type: 'string', description: 'MCP tool name (for MCP routes)' },
                name: { type: 'string', description: 'Display name' },
            },
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRoutesMcpTools.prototype, "createRoute", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.routes.update',
        description: 'Updates an existing route by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                routeId: { type: 'number', description: 'Route ID' },
                url: { type: 'string', description: 'New URL' },
                method: { type: 'string', description: 'New HTTP method' },
                tool_name: { type: 'string', description: 'New MCP tool name' },
                name: { type: 'string', description: 'New display name' },
            },
            required: ['routeId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRoutesMcpTools.prototype, "updateRoute", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.routes.delete',
        description: 'Deletes one or more routes by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'Route IDs to delete' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRoutesMcpTools.prototype, "deleteRoutes", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.routes.roles.list',
        description: 'Lists roles assigned to a route. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                routeId: { type: 'number', description: 'Route ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
            },
            required: ['routeId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRoutesMcpTools.prototype, "listRouteRoles", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.routes.roles.update',
        description: 'Replaces all roles assigned to a route. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                routeId: { type: 'number', description: 'Route ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'Role IDs to assign' },
            },
            required: ['routeId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRoutesMcpTools.prototype, "updateRouteRoles", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.routes.screens.list',
        description: 'Lists screens assigned to a route. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                routeId: { type: 'number', description: 'Route ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
            },
            required: ['routeId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRoutesMcpTools.prototype, "listRouteScreens", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.routes.screens.update',
        description: 'Replaces all screens assigned to a route. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                routeId: { type: 'number', description: 'Route ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'Screen IDs to assign' },
            },
            required: ['routeId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRoutesMcpTools.prototype, "updateRouteScreens", null);
exports.CoreRoutesMcpTools = CoreRoutesMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [route_service_1.RouteService])
], CoreRoutesMcpTools);
//# sourceMappingURL=core-routes.mcp-tools.js.map