// SPDX-License-Identifier: Apache-2.0
import { COMMAND_HANDLER_METADATA, COMMAND_METADATA } from "../Constants";
import { injectable } from "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.
 */
export const CommandHandler = (command) => {
    return (target) => {
        const tgt = target;
        injectable()(tgt);
        const id = crypto.randomUUID();
        if (!Reflect.hasMetadata(COMMAND_METADATA, command)) {
            Reflect.defineMetadata(COMMAND_METADATA, { id }, command);
        }
        Reflect.defineMetadata(COMMAND_HANDLER_METADATA, command, target);
    };
};
