"use strict";
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandHandler = void 0;
const Constants_1 = require("../Constants");
const tsyringe_1 = require("tsyringe");
/**
 * This decorator determines that a class is a command handler
 *
 * The decorated class must implement the `CommandHandler` interface.
 *
 * @param command command *type* to be handled by this handler.
 */
const CommandHandler = (command) => {
    return (target) => {
        const tgt = target;
        (0, tsyringe_1.injectable)()(tgt);
        const id = crypto.randomUUID();
        if (!Reflect.hasMetadata(Constants_1.COMMAND_METADATA, command)) {
            Reflect.defineMetadata(Constants_1.COMMAND_METADATA, { id }, command);
        }
        Reflect.defineMetadata(Constants_1.COMMAND_HANDLER_METADATA, command, target);
    };
};
exports.CommandHandler = CommandHandler;
