import {
  PropertyKeyType,
} from '../type';

import {
  TypeUtil,
} from '../util/TypeUtil';

import { Class } from './Class';
import { Executable } from './Executable';

export class Constructor extends Executable {
  private _rawConstructor: Function;

  public constructor(declaringClazz: Class, parameterTypes?: any[]) {
    super(declaringClazz, CONSTRUCTOR_NAME, parameterTypes);
    this._rawConstructor = TypeUtil.getPrototype(declaringClazz.getType())[CONSTRUCTOR_NAME];
  }

  public newInstance(...args: any[]): any {
    const ctor = this.getDeclaringClass().getType();
    return new (ctor.bind.apply(ctor, [null].concat(args)))();
  }
}

const CONSTRUCTOR_NAME = 'constructor';
