/* eslint-disable no-undef, no-unused-vars, no-redeclare */

// package: lnks.nstd
// file: filesystem.proto

var filesystem_pb = require("./filesystem_pb");
var grpc = require("@improbable-eng/grpc-web").grpc;

var Filesystem = (function () {
  function Filesystem() {}
  Filesystem.serviceName = "lnks.nstd.Filesystem";
  return Filesystem;
}());

Filesystem.Stat = {
  methodName: "Stat",
  service: Filesystem,
  requestStream: false,
  responseStream: false,
  requestType: filesystem_pb.Path,
  responseType: filesystem_pb.FileInfo
};

Filesystem.Mkdir = {
  methodName: "Mkdir",
  service: Filesystem,
  requestStream: false,
  responseStream: false,
  requestType: filesystem_pb.MkdirRequest,
  responseType: filesystem_pb.Path
};

Filesystem.Rmdir = {
  methodName: "Rmdir",
  service: Filesystem,
  requestStream: false,
  responseStream: false,
  requestType: filesystem_pb.RmdirRequest,
  responseType: filesystem_pb.Path
};

exports.Filesystem = Filesystem;

function FilesystemClient(serviceHost, options) {
  this.serviceHost = serviceHost;
  this.options = options || {};
}

FilesystemClient.prototype.stat = function stat(requestMessage, metadata, callback) {
  if (arguments.length === 2) {
    callback = arguments[1];
  }
  var client = grpc.unary(Filesystem.Stat, {
    request: requestMessage,
    host: this.serviceHost,
    metadata: metadata,
    transport: this.options.transport,
    debug: this.options.debug,
    onEnd: function (response) {
      if (callback) {
        if (response.status !== grpc.Code.OK) {
          var err = new Error(response.statusMessage);
          err.code = response.status;
          err.metadata = response.trailers;
          callback(err, null);
        } else {
          callback(null, response.message);
        }
      }
    }
  });
  return {
    cancel: function () {
      callback = null;
      client.close();
    }
  };
};

FilesystemClient.prototype.mkdir = function mkdir(requestMessage, metadata, callback) {
  if (arguments.length === 2) {
    callback = arguments[1];
  }
  var client = grpc.unary(Filesystem.Mkdir, {
    request: requestMessage,
    host: this.serviceHost,
    metadata: metadata,
    transport: this.options.transport,
    debug: this.options.debug,
    onEnd: function (response) {
      if (callback) {
        if (response.status !== grpc.Code.OK) {
          var err = new Error(response.statusMessage);
          err.code = response.status;
          err.metadata = response.trailers;
          callback(err, null);
        } else {
          callback(null, response.message);
        }
      }
    }
  });
  return {
    cancel: function () {
      callback = null;
      client.close();
    }
  };
};

FilesystemClient.prototype.rmdir = function rmdir(requestMessage, metadata, callback) {
  if (arguments.length === 2) {
    callback = arguments[1];
  }
  var client = grpc.unary(Filesystem.Rmdir, {
    request: requestMessage,
    host: this.serviceHost,
    metadata: metadata,
    transport: this.options.transport,
    debug: this.options.debug,
    onEnd: function (response) {
      if (callback) {
        if (response.status !== grpc.Code.OK) {
          var err = new Error(response.statusMessage);
          err.code = response.status;
          err.metadata = response.trailers;
          callback(err, null);
        } else {
          callback(null, response.message);
        }
      }
    }
  });
  return {
    cancel: function () {
      callback = null;
      client.close();
    }
  };
};

exports.FilesystemClient = FilesystemClient;

