// SPDX-License-Identifier: Apache-2.0
import { QUERY_HANDLER_METADATA, QUERY_METADATA } from "../Constants";
import { injectable } from "tsyringe";
/**
 * This decorator determines that a class is a query handler
 *
 * The decorated class must implement the `QueryHandler` interface.
 *
 * @param query query *type* to be handled by this handler.
 */
export const QueryHandler = (query) => {
    return (target) => {
        injectable()(target);
        if (!Reflect.hasMetadata(QUERY_METADATA, query)) {
            Reflect.defineMetadata(QUERY_METADATA, { id: crypto.randomUUID() }, query);
        }
        Reflect.defineMetadata(QUERY_HANDLER_METADATA, query, target);
    };
};
