/**
 * Start Feature Deployment Use Case
 *
 * Starts a local dev server for a feature's git worktree.
 *
 * Business Rules:
 * - featureId must be non-empty
 * - Feature must exist in the repository
 * - The feature's worktree path must exist on disk
 * - Rejects deployments targeting the currently running Shep instance's
 *   own repository (would create a conflicting nested Shep process)
 *
 * Returns the deployment status after the start call (Booting).
 */
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 { DeploymentState } from '../../../domain/generated/output.js';
let StartFeatureDeploymentUseCase = class StartFeatureDeploymentUseCase {
    featureRepo;
    deploymentService;
    fileSystem;
    shepInstance;
    worktreePaths;
    constructor(featureRepo, deploymentService, fileSystem, shepInstance, worktreePaths) {
        this.featureRepo = featureRepo;
        this.deploymentService = deploymentService;
        this.fileSystem = fileSystem;
        this.shepInstance = shepInstance;
        this.worktreePaths = worktreePaths;
    }
    async execute(featureId) {
        if (!featureId?.trim()) {
            throw new Error('featureId is required');
        }
        const feature = await this.featureRepo.findById(featureId);
        if (!feature) {
            throw new Error(`Feature not found: ${featureId}`);
        }
        if (this.shepInstance.isSameInstance(feature.repositoryPath)) {
            throw new Error('Cannot start a dev server for features of the repository Shep is running from');
        }
        const worktreePath = feature.worktreePath ??
            this.worktreePaths.getWorktreePath(feature.repositoryPath, feature.branch);
        if (!this.fileSystem.pathExists(worktreePath)) {
            throw new Error(`Worktree path does not exist: ${worktreePath}`);
        }
        this.deploymentService.start(featureId, worktreePath, 'feature');
        return { state: DeploymentState.Booting, url: null };
    }
};
StartFeatureDeploymentUseCase = __decorate([
    injectable(),
    __param(0, inject('IFeatureRepository')),
    __param(1, inject('IDeploymentService')),
    __param(2, inject('IFileSystemService')),
    __param(3, inject('IShepInstanceService')),
    __param(4, inject('IWorktreePathProvider')),
    __metadata("design:paramtypes", [Object, Object, Object, Object, Object])
], StartFeatureDeploymentUseCase);
export { StartFeatureDeploymentUseCase };
