import { backend_config} from './interface/interface';
import Graph from './graph';

export default  abstract class Runtime{
  //  protected modelConfig_:backend_config = <any>{};
    protected graph_:Graph = null as unknown as Graph;
    constructor(){};
    
    abstract createGraph(config:backend_config);
    //we keep all the init work in this function except forward
    abstract prepare():Promise<number>;

    abstract forward(ifGetOutput?:boolean): any|Promise<ArrayBuffer[]>;

    //release all the resources
    abstract release();

    //give one or more arrayBuffer to initialize input of network
    setInputByArrayBuffer(data : ArrayBuffer[]):number{
        return (this.graph_).setInputFromArrayBuffer(data);
    }
    
    //give one arrayBuffer to initialize input of network
    getArrayBufferOutput():Promise<ArrayBuffer[]>{
        return (this.graph_).getArrayBufferOutput();
    }

    getInputShapeByIndex(idx:number):any{
        return (this.graph_).getInputTensorShape(idx);
    }

    getOutputShapeByIndex(idx:number):any{
        return (this.graph_).getOutputTensorShape(idx);
    }

    getInputCount():number{
        return (this.graph_).getInputTensorCount();
    }

    getOutputCount():number{
        return (this.graph_).getOutputTensorCount();
    }

    //can be used for synchronization
    finishWork():Promise<undefined[]>{
        return (this.graph_).finish();
    }
} 

