"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.CoreFilesMcpTools = void 0;
const common_1 = require("@nestjs/common");
const file_service_1 = require("../../file/file.service");
const mcp_tool_decorator_1 = require("../decorators/mcp-tool.decorator");
let CoreFilesMcpTools = class CoreFilesMcpTools {
    constructor(fileService) {
        this.fileService = fileService;
    }
    async listFiles(args, _context) {
        var _a, _b, _c, _d, _e;
        return this.fileService.getFiles({
            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 getFile(args, _context) {
        return this.fileService.get(args.fileId);
    }
    async getOpenUrl(args, _context) {
        const file = await this.fileService.get(args.fileId);
        const url = await this.fileService.tempOpenURL(file.path);
        return { url };
    }
    async getDownloadUrl(args, _context) {
        const file = await this.fileService.get(args.fileId);
        const url = await this.fileService.tempURL(file.path);
        return { url };
    }
    async deleteFiles(args, context) {
        return this.fileService.delete(context.locale, { ids: args.ids });
    }
};
exports.CoreFilesMcpTools = CoreFilesMcpTools;
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.files.list',
        description: 'Lists uploaded files 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' },
                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)
], CoreFilesMcpTools.prototype, "listFiles", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.files.get',
        description: 'Returns file details by ID. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                fileId: { type: 'number', description: 'File ID' },
            },
            required: ['fileId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreFilesMcpTools.prototype, "getFile", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.files.open-url',
        description: 'Returns a temporary URL to open/view a file inline. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                fileId: { type: 'number', description: 'File ID' },
            },
            required: ['fileId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreFilesMcpTools.prototype, "getOpenUrl", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.files.download-url',
        description: 'Returns a temporary URL to download a file. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                fileId: { type: 'number', description: 'File ID' },
            },
            required: ['fileId'],
        },
        readOnly: true,
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreFilesMcpTools.prototype, "getDownloadUrl", null);
__decorate([
    (0, mcp_tool_decorator_1.McpTool)({
        name: 'core.files.delete',
        description: 'Deletes one or more files by their IDs. Admin only.',
        inputSchema: {
            type: 'object',
            properties: {
                ids: { type: 'array', items: { type: 'number' }, description: 'File IDs to delete' },
            },
            required: ['ids'],
        },
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], CoreFilesMcpTools.prototype, "deleteFiles", null);
exports.CoreFilesMcpTools = CoreFilesMcpTools = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [file_service_1.FileService])
], CoreFilesMcpTools);
//# sourceMappingURL=core-files.mcp-tools.js.map