/**
 * ListToolsUseCase
 *
 * Returns all tools from the JSON source of truth, each enriched with
 * live ToolInstallationStatus via IToolInstallerService.checkAvailability().
 * Platform-specific fields (openDirectory, installCommand) are pre-resolved
 * so the DTO is fully serialisable with no union types.
 */
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 ListToolsUseCase = class ListToolsUseCase {
    toolInstallerService;
    toolMetadata;
    constructor(toolInstallerService, toolMetadata) {
        this.toolInstallerService = toolInstallerService;
        this.toolMetadata = toolMetadata;
    }
    async execute() {
        const entries = this.toolMetadata.getAllEntries();
        const currentPlatform = platform();
        const results = await Promise.all(entries.map(async ([id, metadata]) => {
            let status;
            try {
                status = await this.toolInstallerService.checkAvailability(id);
            }
            catch {
                status = { status: 'error', toolName: id, errorMessage: 'Availability check failed' };
            }
            return {
                id,
                name: metadata.name,
                summary: metadata.summary,
                description: metadata.description,
                tags: metadata.tags,
                iconUrl: metadata.iconUrl,
                autoInstall: metadata.autoInstall ?? true,
                required: metadata.required ?? false,
                openDirectory: resolvePlatformString(metadata.openDirectory, currentPlatform),
                documentationUrl: metadata.documentationUrl,
                installCommand: metadata.commands[currentPlatform],
                status,
                author: metadata.author,
                website: metadata.website,
                platforms: metadata.platforms,
            };
        }));
        return results;
    }
};
ListToolsUseCase = __decorate([
    injectable(),
    __param(0, inject('IToolInstallerService')),
    __param(1, inject('IToolMetadataProvider')),
    __metadata("design:paramtypes", [Object, Object])
], ListToolsUseCase);
export { ListToolsUseCase };
