import { SwiftPackageBuilder } from './operations/SwiftPackageBuilder.js';
import { SwiftPackageTester } from './operations/SwiftPackageTester.js';
import { SwiftPackageRunner } from './operations/SwiftPackageRunner.js';
import { SwiftPackageCleaner } from './operations/SwiftPackageCleaner.js';
import { createModuleLogger } from '../../logger.js';
import * as pathModule from 'path';
import { existsSync } from 'fs';
const logger = createModuleLogger('SwiftPackage');
/**
 * Represents a Swift package (Package.swift)
 * Implements Project, Buildable, Testable, Runnable, and Cleanable interfaces
 */
export class SwiftPackage {
    path;
    name;
    type = 'swiftpackage';
    // Composed operations (Single Responsibility for each)
    builder;
    tester;
    runner;
    cleaner;
    constructor(path, operations) {
        this.path = path;
        // Validate that Package.swift exists
        const packageSwiftPath = pathModule.join(this.path, 'Package.swift');
        if (!existsSync(packageSwiftPath)) {
            throw new Error(`No Package.swift found at: ${this.path}`);
        }
        // Extract name from directory
        this.name = pathModule.basename(this.path);
        // Initialize operations (Dependency Injection)
        this.builder = operations?.builder || new SwiftPackageBuilder();
        this.tester = operations?.tester || new SwiftPackageTester();
        this.runner = operations?.runner || new SwiftPackageRunner();
        this.cleaner = operations?.cleaner || new SwiftPackageCleaner();
        logger.debug({ path: this.path, name: this.name }, 'SwiftPackage created');
    }
    /**
     * Build the package
     */
    async build(options) {
        logger.info({ path: this.path, options }, 'Building Swift package');
        return await this.builder.build(this.path, options);
    }
    /**
     * Run tests for the package
     */
    async test(options) {
        logger.info({ path: this.path, options }, 'Testing Swift package');
        return await this.tester.test(this.path, options);
    }
    /**
     * Run the package executable
     */
    async run(options) {
        logger.info({ path: this.path, options }, 'Running Swift package');
        return await this.runner.run(this.path, options);
    }
    /**
     * Clean build artifacts
     */
    async clean(options) {
        logger.info({ path: this.path, options }, 'Cleaning Swift package');
        await this.cleaner.clean(this.path, options);
    }
}
//# sourceMappingURL=SwiftPackage.js.map