import { Injectable } from '@angular/core';
import { NatsService } from 'app/core/nats/services/nats.service';
import * as nats from 'nats.ws';

import { Error } from 'app/modules/proto/protobuf/rpc_pb';

import {
  ListMemberBankWithdrawsRequest,
  ListMemberBankWithdrawsResponse,
  CreateMemberBankWithdrawRequest,
  CreateMemberBankWithdrawResponse,
  UpdateMemberBankWithdrawRequest,
  UpdateMemberBankWithdrawResponse,
  DeleteMemberBankWithdrawRequest,
  DeleteMemberBankWithdrawResponse,
  GetMemberBankWithdrawResponse,
  GetMemberBankWithdrawRequest,
  UpdateMemberBankWithdrawForStateResponse,
  UpdateMemberBankWithdrawForStateRequest,
} from 'app/modules/proto/c2se/member_bank_withdraw_pb';
import {
  SUBJECT_LIST_MEMBER_BANK_WITHDRAWS,
  SUBJECT_CREATE_MEMBER_BANK_WITHDRAW,
  SUBJECT_UPDATE_MEMBER_BANK_WITHDRAW,
  SUBJECT_DELETE_MEMBER_BANK_WITHDRAW,
  SUBJECT_GET_MEMBER_BANK_WITHDRAW,
  SUBJECT_UPDATE_MEMBER_BANK_WITHDRAW_FOR_STATE,
} from 'app/modules/proto/c2se/backend/member_bank_withdraw_pb';

@Injectable({
  providedIn: 'root',
})
export class MemberBankWithdrawService {
  /**
   * Constructor
   */
  constructor(private __natsService: NatsService) {}

  // -----------------------------------------------------------------------------------------------------
  // @ Accessors
  // -----------------------------------------------------------------------------------------------------

  // -----------------------------------------------------------------------------------------------------
  // @ Public methods
  // -----------------------------------------------------------------------------------------------------

  createMemberBankWithdraw(): Promise<CreateMemberBankWithdrawResponse.Result> {
    return new Promise<CreateMemberBankWithdrawResponse.Result>(
      (resolve, reject) => {
        let req = new CreateMemberBankWithdrawRequest();

        this.__natsService
          .request<CreateMemberBankWithdrawResponse.Result>(
            SUBJECT_CREATE_MEMBER_BANK_WITHDRAW,
            req.serializeBinary(),
            CreateMemberBankWithdrawResponse.deserializeBinary
          )
          .then((result) => {
            console.log('success', result, result.getMemberBankWithdraw());
            return resolve(result);
          })
          .catch((e: Error) => {
            console.log('failed', e);
            return reject(e);
          });
      }
    );
  }

  listMemberBankWithdraws(): Promise<ListMemberBankWithdrawsResponse.Result> {
    return new Promise<ListMemberBankWithdrawsResponse.Result>(
      (resolve, reject) => {
        let req = new ListMemberBankWithdrawsRequest();

        this.__natsService
          .request<ListMemberBankWithdrawsResponse.Result>(
            SUBJECT_LIST_MEMBER_BANK_WITHDRAWS,
            req.serializeBinary(),
            ListMemberBankWithdrawsResponse.deserializeBinary
          )
          .then((result) => {
            console.log('success', result, result.getMemberBankWithdrawsList());
            return resolve(result);
          })
          .catch((e: Error) => {
            console.log('failed', e);
            reject(e);
          });
      }
    );
  }

  getMemberBankWithdraw(): Promise<GetMemberBankWithdrawResponse.Result> {
    return new Promise<GetMemberBankWithdrawResponse.Result>(
      (resolve, reject) => {
        let req = new GetMemberBankWithdrawRequest();

        this.__natsService
          .request<GetMemberBankWithdrawResponse.Result>(
            SUBJECT_GET_MEMBER_BANK_WITHDRAW,
            req.serializeBinary(),
            GetMemberBankWithdrawResponse.deserializeBinary
          )
          .then((result) => {
            console.log('success', result, result.getMemberBankWithdraw());
            return resolve(result);
          })
          .catch((e: Error) => {
            console.log('failed', e);
            return reject(e);
          });
      }
    );
  }

  updateMemberBankWithdraw(): Promise<UpdateMemberBankWithdrawResponse.Result> {
    return new Promise<UpdateMemberBankWithdrawResponse.Result>(
      (resolve, reject) => {
        let req = new UpdateMemberBankWithdrawRequest();

        this.__natsService
          .request<UpdateMemberBankWithdrawResponse.Result>(
            SUBJECT_UPDATE_MEMBER_BANK_WITHDRAW,
            req.serializeBinary(),
            UpdateMemberBankWithdrawResponse.deserializeBinary
          )
          .then((result) => {
            console.log('success', result, result.getMemberBankWithdraw());
            return resolve(result);
          })
          .catch((e: Error) => {
            console.log('failed', e);
            return reject(e);
          });
      }
    );
  }

  updateMemberBankWithdrawForState(): Promise<UpdateMemberBankWithdrawForStateResponse.Result> {
    return new Promise<UpdateMemberBankWithdrawForStateResponse.Result>(
      (resolve, reject) => {
        let req = new UpdateMemberBankWithdrawForStateRequest();

        this.__natsService
          .request<UpdateMemberBankWithdrawForStateResponse.Result>(
            SUBJECT_UPDATE_MEMBER_BANK_WITHDRAW_FOR_STATE,
            req.serializeBinary(),
            UpdateMemberBankWithdrawForStateResponse.deserializeBinary
          )
          .then((result) => {
            console.log('success', result, result.getMemberBankWithdraw());
            return resolve(result);
          })
          .catch((e: Error) => {
            console.log('failed', e);
            return reject(e);
          });
      }
    );
  }

  deleteMemberBankWithdraw(): Promise<DeleteMemberBankWithdrawResponse.Result> {
    return new Promise<DeleteMemberBankWithdrawResponse.Result>(
      (resolve, reject) => {
        let req = new DeleteMemberBankWithdrawRequest();

        this.__natsService
          .request<DeleteMemberBankWithdrawResponse.Result>(
            SUBJECT_DELETE_MEMBER_BANK_WITHDRAW,
            req.serializeBinary(),
            DeleteMemberBankWithdrawResponse.deserializeBinary
          )
          .then((result) => {
            console.log('success', result);
            return resolve(result);
          })
          .catch((e: Error) => {
            console.log('failed', e);
            return reject(e);
          });
      }
    );
  }
}
