/**
 * Get Bedrock Memory Snapshot Use Case
 *
 * Reads the on-disk `.bedrock/` memory store for a given target
 * (Application | Repository | Feature) and returns a typed snapshot
 * the web visualization can render. Resolves the worktree path from
 * the target's owning entity:
 *
 *   - Application → application.repositoryPath
 *   - Repository  → repository.path
 *   - Feature     → feature.worktreePath ?? feature.repositoryPath
 *
 * This use case is the foundation of the BedrockMemoryPanel — it lets
 * users SEE which markdown memory files bedrock has captured (sizes,
 * mtimes, preview), not just whether the integration is enabled.
 *
 * No persistence side-effects, no subprocess invocation. Errors from
 * the underlying reader are swallowed (the reader contract returns a
 * `present: false` snapshot rather than throwing) so the UI can render
 * an empty state regardless of host filesystem quirks.
 */
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 __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { injectable, inject } from 'tsyringe';
import { ApplicationNotFoundError } from '../../../domain/errors/application-not-found.error.js';
import { BedrockTargetKind } from '../../../domain/generated/output.js';
let GetBedrockMemorySnapshotUseCase = class GetBedrockMemorySnapshotUseCase {
    appRepo;
    repoRepo;
    featureRepo;
    reader;
    constructor(appRepo, repoRepo, featureRepo, reader) {
        this.appRepo = appRepo;
        this.repoRepo = repoRepo;
        this.featureRepo = featureRepo;
        this.reader = reader;
    }
    async execute(input) {
        const cwd = await this.resolveCwd(input.kind, input.id);
        return this.reader.read({
            cwd,
            ...(input.previewBytes !== undefined ? { previewBytes: input.previewBytes } : {}),
        });
    }
    async resolveCwd(kind, id) {
        switch (kind) {
            case BedrockTargetKind.Application: {
                const app = await this.appRepo.findById(id);
                if (!app)
                    throw new ApplicationNotFoundError(id);
                return app.repositoryPath;
            }
            case BedrockTargetKind.Repository: {
                const repo = await this.repoRepo.findById(id);
                if (!repo)
                    throw new Error(`Repository not found: ${id}`);
                return repo.path;
            }
            case BedrockTargetKind.Feature: {
                const feature = await this.featureRepo.findById(id);
                if (!feature)
                    throw new Error(`Feature not found: ${id}`);
                return feature.worktreePath ?? feature.repositoryPath;
            }
            default: {
                const unreachable = kind;
                throw new Error(`Unhandled BedrockTargetKind: ${String(unreachable)}`);
            }
        }
    }
};
GetBedrockMemorySnapshotUseCase = __decorate([
    injectable(),
    __param(0, inject('IApplicationRepository')),
    __param(1, inject('IRepositoryRepository')),
    __param(2, inject('IFeatureRepository')),
    __param(3, inject('IBedrockMemoryReader')),
    __metadata("design:paramtypes", [Object, Object, Object, Object])
], GetBedrockMemorySnapshotUseCase);
export { GetBedrockMemorySnapshotUseCase };
