/**
 * Create Project Use Case
 *
 * Orchestrates "create a new empty project folder under the Shep projects
 * root". Owns the project naming rules (validation, slugification, length
 * cap) and the "must not already exist" guard. Delegates filesystem and git
 * work to IProjectScaffoldService so the application layer remains free of
 * node:fs / child_process imports.
 *
 * Presentation-agnostic: callable from CLI, TUI, and Web identically.
 */
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';
/**
 * Slugify a user-supplied project name into a safe directory name.
 *
 * - Lowercases
 * - Replaces whitespace + invalid chars with `-`
 * - Strips leading/trailing dashes and dots
 * - Caps length so we stay well under Windows' 260-char path limit
 *
 * Exported for unit testing — production callers should use the use case.
 */
export function slugifyProjectName(name) {
    const cleaned = name
        .trim()
        .toLowerCase()
        .replace(/[^a-z0-9._-]+/g, '-')
        .replace(/-+/g, '-')
        .replace(/^[-.]+|[-.]+$/g, '');
    return cleaned.slice(0, 64);
}
let CreateProjectUseCase = class CreateProjectUseCase {
    scaffoldService;
    constructor(scaffoldService) {
        this.scaffoldService = scaffoldService;
    }
    async execute(input) {
        const trimmed = input.name.trim();
        if (!trimmed) {
            return { ok: false, error: 'Project name is required.' };
        }
        const slug = slugifyProjectName(trimmed);
        if (!slug) {
            return {
                ok: false,
                error: 'Project name must contain at least one letter or number.',
            };
        }
        if (await this.scaffoldService.projectExists(slug)) {
            return {
                ok: false,
                error: `A project named "${slug}" already exists. Pick a different name.`,
            };
        }
        try {
            const result = await this.scaffoldService.scaffoldProject({ slug });
            return { ok: true, path: result.path };
        }
        catch (err) {
            return {
                ok: false,
                error: err instanceof Error ? err.message : 'Failed to create project folder.',
            };
        }
    }
};
CreateProjectUseCase = __decorate([
    injectable(),
    __param(0, inject('IProjectScaffoldService')),
    __metadata("design:paramtypes", [Object])
], CreateProjectUseCase);
export { CreateProjectUseCase };
