import { execAsync } from '../../../utils.js';
import { createModuleLogger } from '../../../logger.js';
const logger = createModuleLogger('SwiftPackageBuilder');
/**
 * Handles building Swift packages (Single Responsibility: Building)
 */
export class SwiftPackageBuilder {
    /**
     * Build a Swift package
     */
    async build(packagePath, options = {}) {
        const { configuration = 'Debug', product, target } = options;
        // Convert to lowercase for swift command
        const configFlag = configuration.toLowerCase();
        let command = `swift build --package-path "${packagePath}" -c ${configFlag}`;
        if (product) {
            command += ` --product "${product}"`;
        }
        if (target) {
            command += ` --target "${target}"`;
        }
        logger.debug({ command }, 'Build command');
        try {
            const { stdout, stderr } = await execAsync(command, {
                maxBuffer: 10 * 1024 * 1024
            });
            const output = stdout + (stderr ? `\n${stderr}` : '');
            logger.info({ packagePath, configuration }, 'Build succeeded');
            return {
                success: true,
                output
            };
        }
        catch (error) {
            logger.error({ error: error.message, packagePath }, 'Build failed');
            // Return error output for debugging
            const output = (error.stdout || '') + (error.stderr ? `\n${error.stderr}` : '');
            throw new Error(`Build failed: ${error.message}\n${output}`);
        }
    }
}
//# sourceMappingURL=SwiftPackageBuilder.js.map