"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoreUsersMcpTools = void 0;
const common_1 = require("@nestjs/common");
const user_service_1 = require("../../user/user.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreUsersMcpTools = class CoreUsersMcpTools {
    constructor(userService) {
        this.userService = userService;
    }
    async getMe(_args, context) {
        return this.userService.findUserById(context.locale, context.userId);
    }
    async listUsers(args, _context) {
        var _a, _b, _c, _d, _e;
        return this.userService.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 getUser(args, context) {
        return this.userService.get(context.locale, args.userId);
    }
    async createUser(args, context) {
        return this.userService.createWithEmailAndPassword(context.locale, args);
    }
    async updateUser(args, context) {
        return this.userService.update(context.locale, args.userId, { name: args.name });
    }
    async resetPassword(args, context) {
        return this.userService.resetPassword(context.locale, args.userId, { password: args.password });
    }
    async deleteUsers(args, context) {
        return this.userService.delete(context.locale, { ids: args.ids });
    }
    async getUserRoles(args, _context) {
        return this.userService.getUserRoles(args.userId);
    }
    async getUserMenus(args, context) {
        return this.userService.getUserMenus(context.locale, args.userId);
    }
    async getUserRoutes(args, context) {
        return this.userService.getUserRoutes(context.locale, args.userId);
    }
    async assignRole(args, context) {
        return this.userService.assignRoleToUser(context.locale, args.userId, args.roleId);
    }
    async removeRole(args, context) {
        return this.userService.removeRoleFromUser(context.locale, args.userId, args.roleId);
    }
    async verifyIdentifier(args, context) {
        return this.userService.verifyIdentifier(context.locale, args.userId, args.identifierId);
    }
};
exports.CoreUsersMcpTools = CoreUsersMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.me',
        description: 'Returns the authenticated user profile',
        inputSchema: { type: 'object', properties: {} },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "getMe", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.list',
        description: 'Lists all users 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 users' },
                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)
], CoreUsersMcpTools.prototype, "listUsers", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.get',
        description: 'Returns a single user by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { type: 'number', description: 'User ID' },
            },
            required: ['userId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "getUser", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.create',
        description: 'Creates a new user with email and password. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                email: { type: 'string', description: 'User email address' },
                password: { type: 'string', description: 'User password' },
                name: { type: 'string', description: 'User full name' },
            },
            required: ['email', 'password', 'name'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "createUser", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.update',
        description: 'Updates a user name by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { type: 'number', description: 'User ID' },
                name: { type: 'string', description: 'New user name' },
            },
            required: ['userId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "updateUser", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.reset-password',
        description: 'Resets the password of a user by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { type: 'number', description: 'User ID' },
                password: { type: 'string', description: 'New password (must meet strength requirements)' },
            },
            required: ['userId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "resetPassword", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.delete',
        description: 'Deletes one or more users by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: {
                    type: 'array',
                    items: { type: 'number' },
                    description: 'Array of user IDs to delete',
                },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "deleteUsers", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.roles',
        description: 'Returns the roles assigned to a user. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { type: 'number', description: 'User ID' },
            },
            required: ['userId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "getUserRoles", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.menus',
        description: 'Returns the menu items accessible to a user. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { type: 'number', description: 'User ID' },
            },
            required: ['userId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "getUserMenus", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.routes',
        description: 'Returns the routes accessible to a user. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { type: 'number', description: 'User ID' },
            },
            required: ['userId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "getUserRoutes", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.assign-role',
        description: 'Assigns a role to a user. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { type: 'number', description: 'User ID' },
                roleId: { type: 'number', description: 'Role ID to assign' },
            },
            required: ['userId', 'roleId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "assignRole", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.remove-role',
        description: 'Removes a role from a user. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { type: 'number', description: 'User ID' },
                roleId: { type: 'number', description: 'Role ID to remove' },
            },
            required: ['userId', 'roleId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "removeRole", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.users.verify-identifier',
        description: 'Verifies a user identifier (e.g. email confirmation). Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                userId: { type: 'number', description: 'User ID' },
                identifierId: { type: 'number', description: 'Identifier ID to verify' },
            },
            required: ['userId', 'identifierId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreUsersMcpTools.prototype, "verifyIdentifier", null);
exports.CoreUsersMcpTools = CoreUsersMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [user_service_1.UserService])
], CoreUsersMcpTools);
//# sourceMappingURL=core-users.mcp-tools.js.map