import { Injector } from "./Injector";
import { Type, GenericClassDecorator } from "./Util";
import { RPCExporter } from "rpclibrary";

/**
 * @returns {GenericClassDecorator<Type<any>>}
 * @constructor
 */
export function Injectable (_interface?: Type<any>) : GenericClassDecorator<Type<any>> {
  return (target: Type<any>) => {
    Injector.modules.push({
      implements: _interface,
      implementation: target
    })
  }
}

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

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