import "reflect-metadata";
import { INJECT_METADATA_KEY } from "../constants";
import type { ProviderToken } from "../interfaces/provider.interface";

/**
 * Decorator that explicitly specifies a token for dependency injection.
 * Useful when injecting interfaces (via symbols or strings) or when multiple
 * providers are available for the same type.
 *
 * @param token The token to inject
 */
export function Inject(token: ProviderToken): ParameterDecorator {
	return (
		target: object,
		_propertyKey: string | symbol | undefined,
		parameterIndex: number,
	) => {
		const existingInjections =
			Reflect.getMetadata(INJECT_METADATA_KEY, target) || [];
		existingInjections[parameterIndex] = token;
		Reflect.defineMetadata(INJECT_METADATA_KEY, existingInjections, target);
	};
}
