"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.CoreSettingsMcpTools = void 0;
const common_1 = require("@nestjs/common");
const setting_service_1 = require("../../setting/setting.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreSettingsMcpTools = class CoreSettingsMcpTools {
    constructor(settingService) {
        this.settingService = settingService;
    }
    async getEffectiveSettings(_args, context) {
        return this.settingService.getEffectiveSettings(context.userId);
    }
    async setUserSetting(args, context) {
        return this.settingService.setSettingUserValue(context.locale, context.userId, args.slug, args.value);
    }
    async listSettings(args, context) {
        var _a, _b, _c, _d, _e;
        return this.settingService.listSettings(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 getSettingById(args, _context) {
        return this.settingService.get(args.settingId);
    }
    async listSettingGroups(args, context) {
        var _a, _b, _c;
        return this.settingService.listSettingGroups(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: 'id',
            sortOrder: 'asc',
            fields: '',
        });
    }
    async setManySettings(args, _context) {
        return this.settingService.setManySettings(args.settings);
    }
    async updateSettingFromSlug(args, _context) {
        return this.settingService.updateFromSlug(args.slug, { value: args.value });
    }
    async deleteSettings(args, context) {
        return this.settingService.delete(context.locale, { ids: args.ids });
    }
};
exports.CoreSettingsMcpTools = CoreSettingsMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.settings.get',
        description: 'Returns effective settings for the authenticated user',
        inputSchema: { type: 'object', properties: {} },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreSettingsMcpTools.prototype, "getEffectiveSettings", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.settings.set',
        description: 'Updates a user-overridable setting value for the authenticated user. Only settings with user_override=true can be changed.',
        inputSchema: {
            type: 'object',
            properties: {
                slug: {
                    type: 'string',
                    description: 'The slug identifier of the setting to update',
                },
                value: {
                    type: 'string',
                    description: 'The new value for the setting',
                },
            },
            required: ['slug', 'value'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreSettingsMcpTools.prototype, "setUserSetting", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.settings.list',
        description: 'Lists all settings 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)
], CoreSettingsMcpTools.prototype, "listSettings", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.settings.get-by-id',
        description: 'Returns a single setting by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                settingId: { type: 'number', description: 'Setting ID' },
            },
            required: ['settingId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreSettingsMcpTools.prototype, "getSettingById", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.settings.groups.list',
        description: 'Lists setting groups 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' },
            },
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreSettingsMcpTools.prototype, "listSettingGroups", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.settings.set-many',
        description: 'Updates multiple settings at once. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                settings: { type: 'object', description: 'Key-value pairs of slug → value to update' },
            },
            required: ['settings'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreSettingsMcpTools.prototype, "setManySettings", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.settings.update-from-slug',
        description: 'Updates a single setting value by its slug. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                slug: { type: 'string', description: 'Setting slug' },
                value: { type: 'string', description: 'New value' },
            },
            required: ['slug', 'value'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreSettingsMcpTools.prototype, "updateSettingFromSlug", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.settings.delete',
        description: 'Deletes one or more settings by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'Setting IDs to delete' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreSettingsMcpTools.prototype, "deleteSettings", null);
exports.CoreSettingsMcpTools = CoreSettingsMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [setting_service_1.SettingService])
], CoreSettingsMcpTools);
//# sourceMappingURL=core-settings.mcp-tools.js.map