/**
 * LaunchToolUseCase
 *
 * Launches a tool in a target directory by delegating to IIdeLauncherService.
 * Validates tool existence and openDirectory capability before launching.
 * Returns a typed discriminated union result.
 */
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 { platform } from 'node:os';
function resolvePlatformString(value, currentPlatform) {
    if (value == null)
        return undefined;
    if (typeof value === 'string')
        return value;
    return value[currentPlatform];
}
let LaunchToolUseCase = class LaunchToolUseCase {
    ideLauncherService;
    toolMetadata;
    constructor(ideLauncherService, toolMetadata) {
        this.ideLauncherService = ideLauncherService;
        this.toolMetadata = toolMetadata;
    }
    async execute({ toolId, directoryPath, headless }) {
        const metadata = this.toolMetadata.getToolById(toolId);
        if (!metadata) {
            return { ok: false, code: 'tool_not_found', message: `Tool '${toolId}' not found` };
        }
        const openDirectory = resolvePlatformString(metadata.openDirectory, platform());
        if (!openDirectory) {
            return {
                ok: false,
                code: 'not_launchable',
                message: `Tool '${toolId}' has no openDirectory command for this platform`,
            };
        }
        const result = await this.ideLauncherService.launch(toolId, directoryPath, { headless });
        if (!result.ok) {
            return { ok: false, code: 'launch_failed', message: result.message };
        }
        return { ok: true, editorName: result.editorName, path: directoryPath };
    }
};
LaunchToolUseCase = __decorate([
    injectable(),
    __param(0, inject('IIdeLauncherService')),
    __param(1, inject('IToolMetadataProvider')),
    __metadata("design:paramtypes", [Object, Object])
], LaunchToolUseCase);
export { LaunchToolUseCase };
