import { Injector } from "./Injector";
import { Type, GenericClassDecorator } from "./Util";
import { FrontworkComponent } from "../Types/FrontworkComponent";

/**
 * @returns {GenericClassDecorator<Type<any>>}
 * @constructor
 */
export const Module = (...args) : GenericClassDecorator<Type<any>> => {
  return (target: Type<any>) => {
    Injector.rootModules.push(target)
  }
}

/**
 * @returns {GenericClassDecorator<Type<any>>}
 * @constructor
 */
export const RootComponent = (config : {
    rootInterface : Type<any>
    imports : Type<FrontworkComponent>[]
  }) : GenericClassDecorator<Type<any>> => {
  return (target: Type<any>) => {
    Injector.rootModules = config.imports
    Injector.rootInterface = config.rootInterface
    Injector.root = target
  }
}

export const Inject = (type: any) => {
  return function (_this, key) {
    Injector.injectionQueue.push({what: type, target: _this, where:key})
  }
}