export class ValidateConfigUseCase {
    deps;
    constructor(deps) {
        this.deps = deps;
    }
    execute(input) {
        const issues = [];
        if (!this.deps.existsSync(input.configPath)) {
            return { status: 'not-found', issues: [] };
        }
        let config;
        try {
            const raw = this.deps.readFileSync(input.configPath, 'utf-8');
            config = JSON.parse(raw);
        }
        catch {
            issues.push({
                field: 'config.json',
                message: 'Invalid JSON format',
                severity: 'error',
            });
            return { status: 'invalid', issues };
        }
        this.validateServer(config, issues);
        this.validateUser(config, issues);
        this.validateQueue(config, issues);
        this.validateRepositories(config, issues);
        this.validateEnv(input.envPath, issues);
        return {
            status: issues.length > 0 ? 'invalid' : 'valid',
            issues,
        };
    }
    validateServer(config, issues) {
        const server = config.server;
        if (!server) {
            issues.push({ field: 'server', message: 'Missing server section', severity: 'error' });
            return;
        }
        if (typeof server.port !== 'number' || server.port < 1 || server.port > 65535) {
            issues.push({ field: 'server.port', message: 'Port must be between 1 and 65535', severity: 'error' });
        }
    }
    validateUser(config, issues) {
        if (!config.user || typeof config.user !== 'object') {
            issues.push({ field: 'user', message: 'Missing user section', severity: 'error' });
        }
    }
    validateQueue(config, issues) {
        if (!config.queue || typeof config.queue !== 'object') {
            issues.push({ field: 'queue', message: 'Missing queue section', severity: 'error' });
        }
    }
    validateRepositories(config, issues) {
        if (!Array.isArray(config.repositories))
            return;
        for (const repo of config.repositories) {
            const entry = repo;
            if (typeof entry.localPath === 'string' && !this.deps.existsSync(entry.localPath)) {
                issues.push({
                    field: 'repositories',
                    message: `Path does not exist: ${entry.localPath}`,
                    severity: 'error',
                });
            }
        }
    }
    validateEnv(envPath, issues) {
        if (!this.deps.existsSync(envPath)) {
            issues.push({ field: '.env', message: 'Missing .env file', severity: 'error' });
        }
    }
}
//# sourceMappingURL=validateConfig.usecase.js.map