// #region Imports
import 'reflect-metadata';
import { Container } from '../Container';
// #endregion
/**
 * Injects a dependency either into a class field or a constructor parameter.
 * This is now a decorator factory that allows calling it with parentheses.
 *
 * @public
 */
export function Inject(type) {
    return function (target, propertyKey, parameterIndex) {
        if (typeof parameterIndex === 'number') {
            const paramTypes = Reflect.getMetadata('design:paramtypes', target) ?? [];
            const constructor = paramTypes[parameterIndex];
            if (!constructor) {
                console.warn(`Warning: No metadata found for parameter at index ${parameterIndex} in ${target.name}. Fallback to Object.`);
                // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                // @ts-ignore
                target[propertyKey] = {}; // Fallback to a default value or throw an error
            }
            else {
                const instance = Container.instance.get(constructor);
                const existingInjectedParams = Reflect.getOwnMetadata('injectedParams', target) ?? [];
                existingInjectedParams[parameterIndex] = instance;
                Reflect.defineMetadata('injectedParams', existingInjectedParams, target);
            }
        }
        else if (propertyKey) {
            const designType = type ?? Reflect.getMetadata('design:type', target, propertyKey);
            if (!designType) {
                console.warn(`Warning: No metadata found for property "${propertyKey.toString()}" in ${target.constructor.name}. Fallback to Object.`);
                target[propertyKey] = {}; // Fallback to a default value or throw an error
            }
            else {
                const instance = Container.instance.get(designType);
                target[propertyKey] = instance;
            }
        }
    };
}
//# sourceMappingURL=InjectDecorator.js.map