import { NgModule } from '@angular/core';
import { RPCModule } from '@loafer/ng-rpc';

import {
  RPC_CODEC,
  RPC_RWC,
} from '@loafer/ng-rpc/core';
import { JSONRPCClientCodec } from '@loafer/ng-rpc/protocol/json';
import {
  RPCClientWebsocketRWC,
  RxWebsocketSubjectConfig,
} from '@loafer/ng-rpc/client/rwc/websocket';

import { environment } from '../environments/environment';


@NgModule({
  exports: [
    RPCModule,
  ],
  imports: [
    RPCModule.forRoot({}),
  ],
  providers: [
    {provide: 'WEBAPP_RPC_CONFIG', useValue: environment.webappRPCConfig},

    {provide: RPC_CODEC, useFactory: () => new JSONRPCClientCodec()},
    {
      provide: RPC_RWC,
      useFactory: (config: RxWebsocketSubjectConfig) => new RPCClientWebsocketRWC(config),
      deps: ['WEBAPP_RPC_CONFIG']
    },

  ]
})
export class AppRPCModule { }
