import { BinaryWriter } from "../binary";
import { isSet, bytesFromBase64, base64FromBytes } from "../helpers";
/** MsgSignData defines an arbitrary, general-purpose, off-chain message */

/** MsgSignData defines an arbitrary, general-purpose, off-chain message */

/** MsgSignData defines an arbitrary, general-purpose, off-chain message */

/** ListOfMsgSignData defines a list of MsgSignData, used to marshal and unmarshal them in a clean way */

/** ListOfMsgSignData defines a list of MsgSignData, used to marshal and unmarshal them in a clean way */

/** ListOfMsgSignData defines a list of MsgSignData, used to marshal and unmarshal them in a clean way */

function createBaseMsgSignData() {
  return {
    signer: "",
    data: new Uint8Array()
  };
}
export const MsgSignData = {
  typeUrl: "/gitopia.gitopia.offchain.MsgSignData",
  encode(message, writer = BinaryWriter.create()) {
    if (message.signer !== "") {
      writer.uint32(10).string(message.signer);
    }
    if (message.data.length !== 0) {
      writer.uint32(18).bytes(message.data);
    }
    return writer;
  },
  fromJSON(object) {
    return {
      signer: isSet(object.signer) ? String(object.signer) : "",
      data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array()
    };
  },
  fromPartial(object) {
    var _object$signer, _object$data;
    const message = createBaseMsgSignData();
    message.signer = (_object$signer = object.signer) !== null && _object$signer !== void 0 ? _object$signer : "";
    message.data = (_object$data = object.data) !== null && _object$data !== void 0 ? _object$data : new Uint8Array();
    return message;
  },
  fromAmino(object) {
    const message = createBaseMsgSignData();
    if (object.signer !== undefined && object.signer !== null) {
      message.signer = object.signer;
    }
    if (object.data !== undefined && object.data !== null) {
      message.data = bytesFromBase64(object.data);
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.signer = message.signer === "" ? undefined : message.signer;
    obj.data = message.data ? base64FromBytes(message.data) : undefined;
    return obj;
  },
  fromAminoMsg(object) {
    return MsgSignData.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return MsgSignData.decode(message.value);
  },
  toProto(message) {
    return MsgSignData.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.offchain.MsgSignData",
      value: MsgSignData.encode(message).finish()
    };
  }
};
function createBaseListOfMsgSignData() {
  return {
    msgs: []
  };
}
export const ListOfMsgSignData = {
  typeUrl: "/gitopia.gitopia.offchain.ListOfMsgSignData",
  encode(message, writer = BinaryWriter.create()) {
    for (const v of message.msgs) {
      MsgSignData.encode(v, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      msgs: Array.isArray(object === null || object === void 0 ? void 0 : object.msgs) ? object.msgs.map(e => MsgSignData.fromJSON(e)) : []
    };
  },
  fromPartial(object) {
    var _object$msgs;
    const message = createBaseListOfMsgSignData();
    message.msgs = ((_object$msgs = object.msgs) === null || _object$msgs === void 0 ? void 0 : _object$msgs.map(e => MsgSignData.fromPartial(e))) || [];
    return message;
  },
  fromAmino(object) {
    var _object$msgs2;
    const message = createBaseListOfMsgSignData();
    message.msgs = ((_object$msgs2 = object.msgs) === null || _object$msgs2 === void 0 ? void 0 : _object$msgs2.map(e => MsgSignData.fromAmino(e))) || [];
    return message;
  },
  toAmino(message) {
    const obj = {};
    if (message.msgs) {
      obj.msgs = message.msgs.map(e => e ? MsgSignData.toAmino(e) : undefined);
    } else {
      obj.msgs = message.msgs;
    }
    return obj;
  },
  fromAminoMsg(object) {
    return ListOfMsgSignData.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return ListOfMsgSignData.decode(message.value);
  },
  toProto(message) {
    return ListOfMsgSignData.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.offchain.ListOfMsgSignData",
      value: ListOfMsgSignData.encode(message).finish()
    };
  }
};