/** Valid trait name pattern: lowercase alphanumeric + hyphens */
const NAME_PATTERN = /^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/;
export class TraitManager {
    store;
    constructor(store) {
        this.store = store;
    }
    createTrait(opts) {
        const { name, label, description, promptFragment } = opts;
        if (!name || typeof name !== "string") {
            throw new Error("Missing trait name");
        }
        if (!NAME_PATTERN.test(name)) {
            throw new Error("Trait name must be lowercase alphanumeric + hyphens (e.g. 'my-trait')");
        }
        if (this.store.get(name)) {
            throw new Error(`Trait "${name}" already exists`);
        }
        if (!label || typeof label !== "string") {
            throw new Error("Missing trait label");
        }
        const now = Date.now();
        const trait = {
            name,
            label,
            description: description || "",
            promptFragment: promptFragment || "",
            createdAt: now,
            updatedAt: now,
        };
        this.store.put(trait);
        return trait;
    }
    getTrait(name) {
        return this.store.get(name);
    }
    listTraits() {
        return this.store.getAll();
    }
    updateTrait(name, updates) {
        return this.store.update(name, updates);
    }
    deleteTrait(name) {
        const trait = this.store.get(name);
        if (!trait)
            return false;
        this.store.remove(name);
        return true;
    }
    /**
     * Resolve trait names to their definitions.
     * Returns only traits that exist, silently skipping unknown names.
     */
    resolveTraits(names) {
        const result = [];
        for (const name of names) {
            const trait = this.store.get(name);
            if (trait) {
                result.push({ label: trait.label, promptFragment: trait.promptFragment });
            }
        }
        return result;
    }
}
//# sourceMappingURL=trait-manager.js.map