"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.CoreScreensMcpTools = void 0;
const common_1 = require("@nestjs/common");
const api_pagination_1 = require("@hed-hog/api-pagination");
const screen_service_1 = require("../../screen/screen.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreScreensMcpTools = class CoreScreensMcpTools {
    constructor(screenService) {
        this.screenService = screenService;
    }
    async listScreens(args, context) {
        var _a, _b, _c, _d, _e;
        return this.screenService.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 getScreen(args, _context) {
        return this.screenService.get(args.screenId);
    }
    async createScreen(args, _context) {
        return this.screenService.create(args);
    }
    async updateScreen(args, _context) {
        const { screenId } = args, data = __rest(args, ["screenId"]);
        return this.screenService.update({ id: screenId, data: data });
    }
    async deleteScreens(args, _context) {
        return this.screenService.delete({ ids: args.ids });
    }
    async listScreenRoles(args, context) {
        var _a, _b;
        return this.screenService.listRoles(context.locale, args.screenId, {
            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 updateScreenRoles(args, _context) {
        return this.screenService.updateRoles(args.screenId, { ids: args.ids });
    }
    async listScreenRoutes(args, _context) {
        var _a, _b;
        return this.screenService.listRoutes(args.screenId, {
            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 updateScreenRoutes(args, _context) {
        return this.screenService.updateRoutes(args.screenId, { ids: args.ids });
    }
};
exports.CoreScreensMcpTools = CoreScreensMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.screens.list',
        description: 'Lists all screens 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)
], CoreScreensMcpTools.prototype, "listScreens", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.screens.get',
        description: 'Returns a single screen by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                screenId: { type: 'number', description: 'Screen ID' },
            },
            required: ['screenId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreScreensMcpTools.prototype, "getScreen", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.screens.create',
        description: 'Creates a new screen. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                slug: { type: 'string', description: 'Screen slug (unique identifier)' },
                locale: { type: 'object', description: 'Locale translations, e.g. {"en": {"name": "Dashboard"}}' },
            },
            required: ['slug'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreScreensMcpTools.prototype, "createScreen", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.screens.update',
        description: 'Updates an existing screen by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                screenId: { type: 'number', description: 'Screen ID' },
                slug: { type: 'string', description: 'New slug' },
                locale: { type: 'object', description: 'Updated locale translations' },
            },
            required: ['screenId'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreScreensMcpTools.prototype, "updateScreen", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.screens.delete',
        description: 'Deletes one or more screens by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'Screen IDs to delete' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreScreensMcpTools.prototype, "deleteScreens", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.screens.roles.list',
        description: 'Lists roles assigned to a screen. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                screenId: { type: 'number', description: 'Screen ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
            },
            required: ['screenId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreScreensMcpTools.prototype, "listScreenRoles", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.screens.roles.update',
        description: 'Replaces all roles assigned to a screen. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                screenId: { type: 'number', description: 'Screen ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'Role IDs to assign' },
            },
            required: ['screenId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreScreensMcpTools.prototype, "updateScreenRoles", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.screens.routes.list',
        description: 'Lists routes assigned to a screen. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                screenId: { type: 'number', description: 'Screen ID' },
                page: { type: 'number', description: 'Page number (default: 1)' },
                pageSize: { type: 'number', description: 'Items per page (default: 20)' },
            },
            required: ['screenId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreScreensMcpTools.prototype, "listScreenRoutes", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.screens.routes.update',
        description: 'Replaces all routes assigned to a screen. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                screenId: { type: 'number', description: 'Screen ID' },
                ids: { type: 'array', items: { type: 'number' }, description: 'Route IDs to assign' },
            },
            required: ['screenId', 'ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreScreensMcpTools.prototype, "updateScreenRoutes", null);
exports.CoreScreensMcpTools = CoreScreensMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [screen_service_1.ScreenService])
], CoreScreensMcpTools);
//# sourceMappingURL=core-screens.mcp-tools.js.map