"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.CoreRolesMcpTools = void 0;
const common_1 = require("@nestjs/common");
const api_pagination_1 = require("@hed-hog/api-pagination");
const role_service_1 = require("../../role/role.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreRolesMcpTools = class CoreRolesMcpTools {
    constructor(roleService) {
        this.roleService = roleService;
    }
    async listRoles(args, context) {
        var _a, _b, _c, _d, _e;
        return this.roleService.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: '',
        }, context.locale);
    }
    async getRole(args, _context) {
        return this.roleService.get(args.roleId);
    }
    async createRole(args, _context) {
        return this.roleService.create(args);
    }
    async updateRole(args, context) {
        const { roleId } = args, data = __rest(args, ["roleId"]);
        return this.roleService.update(roleId, data, context.locale);
    }
    async deleteRoles(args, context) {
        return this.roleService.delete({ ids: args.ids }, context.locale);
    }
    async listRoleUsers(args, _context) {
        var _a, _b;
        return this.roleService.listUsers(args.roleId, {
            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 updateRoleUsers(args, _context) {
        return this.roleService.updateUsers(args.roleId, { ids: args.ids });
    }
    async listRoleMenus(args, context) {
        var _a, _b;
        return this.roleService.listMenus(context.locale, args.roleId, {
            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 updateRoleMenus(args, _context) {
        return this.roleService.updateMenus(args.roleId, { ids: args.ids });
    }
    async listRoleRoutes(args, _context) {
        var _a, _b;
        return this.roleService.listRoutes(args.roleId, {
            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: '',
        }, args.search, 'contains', args.method);
    }
    async updateRoleRoutes(args, _context) {
        return this.roleService.updateRoutes(args.roleId, { ids: args.ids });
    }
    async listRoleScreens(args, context) {
        var _a, _b;
        return this.roleService.listScreens(context.locale, args.roleId, {
            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 updateRoleScreens(args, _context) {
        return this.roleService.updateScreens(args.roleId, { ids: args.ids });
    }
};
exports.CoreRolesMcpTools = CoreRolesMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.list',
        description: 'Lists all roles 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 to filter roles' },
                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)
], CoreRolesMcpTools.prototype, "listRoles", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.get',
        description: 'Returns a single role by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
            },
            required: ['roleId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "getRole", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.create',
        description: 'Creates a new role. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                slug: { type: 'string', description: 'Role slug (unique identifier)' },
                locale: {
                    type: 'object',
                    description: 'Locale translations keyed by locale code, e.g. {"en": {"name": "Admin", "description": "..."}}',
                },
            },
            required: ['slug'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "createRole", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.update',
        description: 'Updates an existing role by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
                slug: { type: 'string', description: 'New slug' },
                locale: { type: 'object', description: 'Updated locale translations' },
            },
            required: ['roleId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "updateRole", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.delete',
        description: 'Deletes one or more roles by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'Array of role IDs to delete' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "deleteRoles", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.users.list',
        description: 'Lists users assigned to a role. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
            },
            required: ['roleId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "listRoleUsers", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.users.update',
        description: 'Replaces all users assigned to a role. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'User IDs to assign' },
            },
            required: ['roleId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "updateRoleUsers", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.menus.list',
        description: 'Lists menus assigned to a role. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
            },
            required: ['roleId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "listRoleMenus", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.menus.update',
        description: 'Replaces all menus assigned to a role. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'Menu IDs to assign' },
            },
            required: ['roleId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "updateRoleMenus", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.routes.list',
        description: 'Lists routes assigned to a role with optional URL filter. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
                search: { type: 'string', description: 'Search filter for URL' },
                method: { type: 'string', description: 'HTTP method filter (GET, POST, etc.)' },
            },
            required: ['roleId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "listRoleRoutes", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.routes.update',
        description: 'Replaces all routes assigned to a role. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'Route IDs to assign' },
            },
            required: ['roleId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "updateRoleRoutes", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.screens.list',
        description: 'Lists screens assigned to a role. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
            },
            required: ['roleId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "listRoleScreens", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.roles.screens.update',
        description: 'Replaces all screens assigned to a role. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                roleId: { type: 'number', description: 'Role ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'Screen IDs to assign' },
            },
            required: ['roleId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreRolesMcpTools.prototype, "updateRoleScreens", null);
exports.CoreRolesMcpTools = CoreRolesMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [role_service_1.RoleService])
], CoreRolesMcpTools);
//# sourceMappingURL=core-roles.mcp-tools.js.map