/**
 * Create Feature From Remote Use Case
 *
 * Composite use case that chains ImportGitHubRepositoryUseCase with
 * CreateFeatureUseCase. Enables creating a feature on a remote GitHub
 * repo in a single command — clone (or fork), register, then create feature.
 *
 * Provides two execution modes:
 * - execute(): synchronous full flow for CLI
 * - createRecord() + initializeAndSpawn(): two-phase for Web UI (fast response + background work)
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { injectable, inject } from 'tsyringe';
import { ImportGitHubRepositoryUseCase } from '../../repositories/import-github-repository.use-case.js';
import { CreateFeatureUseCase } from './create-feature.use-case.js';
let CreateFeatureFromRemoteUseCase = class CreateFeatureFromRemoteUseCase {
    importUseCase;
    createFeatureUseCase;
    constructor(importUseCase, createFeatureUseCase) {
        this.importUseCase = importUseCase;
        this.createFeatureUseCase = createFeatureUseCase;
    }
    /**
     * Full synchronous execution: import repo then create feature.
     * Used by the CLI which shows a spinner and needs everything done before returning.
     */
    async execute(input) {
        const repository = await this.importUseCase.execute({
            url: input.remoteUrl,
            dest: input.cloneDest,
            defaultCloneDir: input.defaultCloneDir,
            cloneOptions: input.cloneOptions,
            forkOptions: input.forkOptions,
        });
        return this.createFeatureUseCase.execute({
            userInput: input.userInput,
            repositoryPath: repository.path,
            approvalGates: input.approvalGates,
            push: input.push,
            openPr: input.openPr,
            parentId: input.parentId,
            name: input.name,
            description: input.description,
            fast: input.fast,
            pending: input.pending,
            agentType: input.agentType,
            model: input.model,
            attachments: input.attachments,
            sessionId: input.sessionId,
            attachmentPaths: input.attachmentPaths,
        });
    }
    /**
     * Phase 1 (fast): import repo + create DB record. Returns immediately with real feature ID.
     * Used by the Web UI for optimistic display.
     */
    async createRecord(input) {
        const repository = await this.importUseCase.execute({
            url: input.remoteUrl,
            dest: input.cloneDest,
            defaultCloneDir: input.defaultCloneDir,
            cloneOptions: input.cloneOptions,
            forkOptions: input.forkOptions,
        });
        return this.createFeatureUseCase.createRecord({
            userInput: input.userInput,
            repositoryPath: repository.path,
            approvalGates: input.approvalGates,
            push: input.push,
            openPr: input.openPr,
            parentId: input.parentId,
            name: input.name,
            description: input.description,
            fast: input.fast,
            pending: input.pending,
            agentType: input.agentType,
            model: input.model,
            attachments: input.attachments,
            sessionId: input.sessionId,
            attachmentPaths: input.attachmentPaths,
        });
    }
    /**
     * Phase 2 (background): metadata generation, worktree, spec, agent spawn.
     * Fire-and-forget from the Web UI.
     */
    async initializeAndSpawn(feature, input, shouldSpawn) {
        return this.createFeatureUseCase.initializeAndSpawn(feature, {
            userInput: input.userInput,
            // CreateFeatureUseCase.initializeAndSpawn reads the effective repo path
            // from feature.repositoryPath, but the interface still requires this
            // field. Pass the feature's repositoryPath for consistency.
            repositoryPath: feature.repositoryPath,
            approvalGates: input.approvalGates,
            push: input.push,
            openPr: input.openPr,
            parentId: input.parentId,
            name: input.name,
            description: input.description,
            fast: input.fast,
            pending: input.pending,
            agentType: input.agentType,
            model: input.model,
            attachments: input.attachments,
            sessionId: input.sessionId,
            attachmentPaths: input.attachmentPaths,
        }, shouldSpawn);
    }
};
CreateFeatureFromRemoteUseCase = __decorate([
    injectable(),
    __param(0, inject(ImportGitHubRepositoryUseCase)),
    __param(1, inject(CreateFeatureUseCase)),
    __metadata("design:paramtypes", [ImportGitHubRepositoryUseCase,
        CreateFeatureUseCase])
], CreateFeatureFromRemoteUseCase);
export { CreateFeatureFromRemoteUseCase };
