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

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

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

export class Method extends Executable {
  private _returnType: any;
  private _rawMethod: Function;

  public constructor(declaringClazz: Class, name: PropertyKeyType, parameterTypes: any[], returnType: any) {
    super(declaringClazz, name, parameterTypes);
    this._returnType = returnType;
    this._rawMethod = TypeUtil.getPrototype(declaringClazz.getType())[name];
  }

  public getReturnType(): any {
    return this._returnType;
  }

  public invoke(instance: Object, ...args: any[]): any {
    return this._rawMethod.apply(instance, args);
  }
}
