import { XcodeBuild } from './XcodeBuild.js';
import { XcodeArchive } from './XcodeArchive.js';
import { XcodeInfo } from './XcodeInfo.js';
import { createModuleLogger } from '../../logger.js';
import * as pathModule from 'path';
const logger = createModuleLogger('XcodeProject');
/**
 * Represents an Xcode project (.xcodeproj) or workspace (.xcworkspace)
 */
export class XcodeProject {
    path;
    type;
    name;
    build;
    archive;
    info;
    constructor(path, type, components) {
        this.path = path;
        this.type = type;
        // Extract name from path
        const ext = type === 'workspace' ? '.xcworkspace' : '.xcodeproj';
        this.name = pathModule.basename(this.path, ext);
        // Initialize components
        this.build = components?.build || new XcodeBuild();
        this.archive = components?.archive || new XcodeArchive();
        this.info = components?.info || new XcodeInfo();
        logger.debug({ path: this.path, type, name: this.name }, 'XcodeProject created');
    }
    /**
     * Build the project
     */
    async buildProject(options = {}) {
        logger.info({ path: this.path, options }, 'Building Xcode project');
        const isWorkspace = this.type === 'workspace';
        return await this.build.build(this.path, isWorkspace, options);
    }
    /**
     * Run tests for the project
     */
    async test(options = {}) {
        logger.info({ path: this.path, options }, 'Testing Xcode project');
        const isWorkspace = this.type === 'workspace';
        return await this.build.test(this.path, isWorkspace, options);
    }
    /**
     * Archive the project for distribution
     */
    async archiveProject(options) {
        logger.info({ path: this.path, options }, 'Archiving Xcode project');
        const isWorkspace = this.type === 'workspace';
        return await this.archive.archive(this.path, isWorkspace, options);
    }
    /**
     * Export an IPA from an archive
     */
    async exportIPA(archivePath, options = {}) {
        logger.info({ archivePath, options }, 'Exporting IPA');
        return await this.archive.exportIPA(archivePath, options);
    }
    /**
     * Clean build artifacts
     */
    async clean(options = {}) {
        logger.info({ path: this.path, options }, 'Cleaning Xcode project');
        const isWorkspace = this.type === 'workspace';
        await this.build.clean(this.path, isWorkspace, options);
    }
    /**
     * Get list of schemes
     */
    async getSchemes() {
        const isWorkspace = this.type === 'workspace';
        return await this.info.getSchemes(this.path, isWorkspace);
    }
    /**
     * Get list of targets
     */
    async getTargets() {
        const isWorkspace = this.type === 'workspace';
        return await this.info.getTargets(this.path, isWorkspace);
    }
    /**
     * Get build settings for a scheme
     */
    async getBuildSettings(scheme, configuration, platform) {
        const isWorkspace = this.type === 'workspace';
        return await this.info.getBuildSettings(this.path, isWorkspace, scheme, configuration, platform);
    }
    /**
     * Get comprehensive project information
     */
    async getProjectInfo() {
        const isWorkspace = this.type === 'workspace';
        return await this.info.getProjectInfo(this.path, isWorkspace);
    }
    /**
     * Check if this is a workspace
     */
    isWorkspace() {
        return this.type === 'workspace';
    }
    /**
     * Get the project directory
     */
    getDirectory() {
        return pathModule.dirname(this.path);
    }
}
//# sourceMappingURL=XcodeProject.js.map