"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.FilesystemHandler = void 0;
const ipc_1 = require("../ipc");
/**
 * FilesystemHandler - Thin IPC layer for filesystem operations.
 * All business logic lives in FilesystemManager.
 */
let FilesystemHandler = class FilesystemHandler {
    fsManager;
    constructor(fsManager) {
        this.fsManager = fsManager;
    }
    /**
     * Read the contents of a file.
     */
    async handleReadFile(args) {
        const { path: targetPath, encoding = "utf-8" } = args;
        return await this.fsManager.readFile(targetPath, encoding);
    }
    /**
     * Write content to a file, creating directories if needed.
     */
    async handleWriteFile(args) {
        const { path: targetPath, content, encoding = "utf-8" } = args;
        await this.fsManager.writeFile(targetPath, content, encoding);
    }
    /**
     * Check if a file or directory exists.
     */
    async handleExists(args) {
        const { path: targetPath } = args;
        return await this.fsManager.exists(targetPath);
    }
    /**
     * Create a directory and any necessary parent directories.
     */
    async handleMkdir(args) {
        const { path: targetPath } = args;
        await this.fsManager.mkdir(targetPath);
    }
    /**
     * List contents of a directory.
     */
    async handleReaddir(args) {
        const { path: targetPath } = args;
        return await this.fsManager.readdir(targetPath);
    }
    /**
     * Get file or directory statistics.
     */
    async handleStat(args) {
        const { path: targetPath } = args;
        return await this.fsManager.stat(targetPath);
    }
    /**
     * Search for files and directories using glob patterns.
     */
    async handleSearch(args) {
        const { path: basePath, pattern, limit = 10 } = args;
        return await this.fsManager.search(basePath, pattern, limit);
    }
    /**
     * Delete a file or directory.
     * For directories, removes recursively.
     */
    async handleDelete(args) {
        const { path: targetPath } = args;
        await this.fsManager.delete(targetPath);
    }
};
exports.FilesystemHandler = FilesystemHandler;
__decorate([
    (0, ipc_1.EdenHandler)("read", { permission: "read" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], FilesystemHandler.prototype, "handleReadFile", null);
__decorate([
    (0, ipc_1.EdenHandler)("write", { permission: "write" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], FilesystemHandler.prototype, "handleWriteFile", null);
__decorate([
    (0, ipc_1.EdenHandler)("exists", { permission: "read" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], FilesystemHandler.prototype, "handleExists", null);
__decorate([
    (0, ipc_1.EdenHandler)("mkdir", { permission: "write" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], FilesystemHandler.prototype, "handleMkdir", null);
__decorate([
    (0, ipc_1.EdenHandler)("readdir", { permission: "read" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], FilesystemHandler.prototype, "handleReaddir", null);
__decorate([
    (0, ipc_1.EdenHandler)("stat", { permission: "read" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], FilesystemHandler.prototype, "handleStat", null);
__decorate([
    (0, ipc_1.EdenHandler)("search", { permission: "read" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], FilesystemHandler.prototype, "handleSearch", null);
__decorate([
    (0, ipc_1.EdenHandler)("delete", { permission: "write" }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], FilesystemHandler.prototype, "handleDelete", null);
exports.FilesystemHandler = FilesystemHandler = __decorate([
    (0, ipc_1.EdenNamespace)("fs"),
    __metadata("design:paramtypes", [Function])
], FilesystemHandler);
//# sourceMappingURL=FilesystemHandler.js.map