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 startTime = Date.now();
        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}` : '');
            const duration = Date.now() - startTime;
            logger.info({ packagePath, configuration, duration }, 'Build succeeded');
            return {
                success: true,
                output,
                duration
            };
        }
        catch (error) {
            const duration = Date.now() - startTime;
            logger.error({ error: error.message, packagePath }, 'Build failed');
            const output = (error.stdout || '') + (error.stderr ? `\n${error.stderr}` : '');
            return {
                success: false,
                output,
                error: error.message,
                duration
            };
        }
    }
}
//# sourceMappingURL=SwiftPackageBuilder.js.map