"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.CoreMenusMcpTools = void 0;
const common_1 = require("@nestjs/common");
const api_pagination_1 = require("@hed-hog/api-pagination");
const menu_service_1 = require("../../menu/menu.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreMenusMcpTools = class CoreMenusMcpTools {
    constructor(menuService) {
        this.menuService = menuService;
    }
    async getSystemMenu(_args, context) {
        return this.menuService.getSystemMenu(context.locale, context.userId);
    }
    async getMenuStats(_args, _context) {
        return this.menuService.stats();
    }
    async listAllMenus(_args, context) {
        return this.menuService.listAll(context.locale);
    }
    async listMenus(args, context) {
        var _a, _b, _c, _d, _e;
        return this.menuService.list(context.locale, {
            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 getMenu(args, context) {
        return this.menuService.get(context.locale, args.menuId);
    }
    async createMenu(args, context) {
        return this.menuService.create(context.locale, args);
    }
    async updateMenu(args, context) {
        const { menuId } = args, data = __rest(args, ["menuId"]);
        return this.menuService.update(context.locale, { id: menuId, data: data });
    }
    async deleteMenus(args, context) {
        return this.menuService.delete(context.locale, { ids: args.ids });
    }
    async updateMenuOrder(args, context) {
        return this.menuService.updateOrder(context.locale, { ids: args.ids });
    }
    async listMenuRoles(args, context) {
        var _a, _b;
        return this.menuService.listRoles(context.locale, args.menuId, {
            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 updateMenuRoles(args, context) {
        return this.menuService.updateRoles(context.locale, args.menuId, { ids: args.ids });
    }
};
exports.CoreMenusMcpTools = CoreMenusMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.system',
        description: 'Returns the system menu for the authenticated user.',
        inputSchema: { type: 'object', properties: {} },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "getSystemMenu", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.stats',
        description: 'Returns menu statistics. Admin only.',
        inputSchema: { type: 'object', properties: {} },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "getMenuStats", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.all',
        description: 'Returns all menus as a flat list (no pagination). Admin only.',
        inputSchema: { type: 'object', properties: {} },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "listAllMenus", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.list',
        description: 'Lists menus with 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)
], CoreMenusMcpTools.prototype, "listMenus", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.get',
        description: 'Returns a single menu by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                menuId: { type: 'number', description: 'Menu ID' },
            },
            required: ['menuId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "getMenu", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.create',
        description: 'Creates a new menu item. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                slug: { type: 'string', description: 'Menu slug' },
                url: { type: 'string', description: 'Target URL' },
                icon: { type: 'string', description: 'Icon identifier' },
                order: { type: 'number', description: 'Display order' },
                menu_id: { type: 'number', description: 'Parent menu ID' },
                locale: { type: 'object', description: 'Locale translations, e.g. {"en": {"name": "Dashboard"}}' },
            },
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "createMenu", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.update',
        description: 'Updates an existing menu item by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                menuId: { type: 'number', description: 'Menu ID' },
                slug: { type: 'string', description: 'New slug' },
                url: { type: 'string', description: 'New URL' },
                icon: { type: 'string', description: 'New icon' },
                order: { type: 'number', description: 'New display order' },
                menu_id: { type: 'number', description: 'New parent menu ID' },
                locale: { type: 'object', description: 'Updated locale translations' },
            },
            required: ['menuId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "updateMenu", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.delete',
        description: 'Deletes one or more menu items by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'Menu IDs to delete' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "deleteMenus", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.order',
        description: 'Updates the display order of menus. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'Menu IDs in the desired order' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "updateMenuOrder", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.roles.list',
        description: 'Lists roles assigned to a menu. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                menuId: { type: 'number', description: 'Menu ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
            },
            required: ['menuId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "listMenuRoles", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.menus.roles.update',
        description: 'Replaces all roles assigned to a menu. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                menuId: { type: 'number', description: 'Menu ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'Role IDs to assign' },
            },
            required: ['menuId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreMenusMcpTools.prototype, "updateMenuRoles", null);
exports.CoreMenusMcpTools = CoreMenusMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [menu_service_1.MenuService])
], CoreMenusMcpTools);
//# sourceMappingURL=core-menus.mcp-tools.js.map