//@ts-nocheck
import { Coin } from "../../../../cosmos/base/v1beta1/coin";
import * as _m0 from "protobufjs/minimal";
import { isSet } from "../../../../helpers";
/** Allocation defines the spend limit for a particular port and channel */

/** Allocation defines the spend limit for a particular port and channel */

/**
 * TransferAuthorization allows the grantee to spend up to spend_limit coins from
 * the granter's account for ibc transfer on a specific channel
 */

/**
 * TransferAuthorization allows the grantee to spend up to spend_limit coins from
 * the granter's account for ibc transfer on a specific channel
 */

function createBaseAllocation() {
  return {
    sourcePort: "",
    sourceChannel: "",
    spendLimit: [],
    allowList: [],
    allowedPacketData: []
  };
}
export const Allocation = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.sourcePort !== "") {
      writer.uint32(10).string(message.sourcePort);
    }
    if (message.sourceChannel !== "") {
      writer.uint32(18).string(message.sourceChannel);
    }
    for (const v of message.spendLimit) {
      Coin.encode(v, writer.uint32(26).fork()).ldelim();
    }
    for (const v of message.allowList) {
      writer.uint32(34).string(v);
    }
    for (const v of message.allowedPacketData) {
      writer.uint32(42).string(v);
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseAllocation();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.sourcePort = reader.string();
          break;
        case 2:
          message.sourceChannel = reader.string();
          break;
        case 3:
          message.spendLimit.push(Coin.decode(reader, reader.uint32()));
          break;
        case 4:
          message.allowList.push(reader.string());
          break;
        case 5:
          message.allowedPacketData.push(reader.string());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      sourcePort: isSet(object.sourcePort) ? String(object.sourcePort) : "",
      sourceChannel: isSet(object.sourceChannel) ? String(object.sourceChannel) : "",
      spendLimit: Array.isArray(object === null || object === void 0 ? void 0 : object.spendLimit) ? object.spendLimit.map(e => Coin.fromJSON(e)) : [],
      allowList: Array.isArray(object === null || object === void 0 ? void 0 : object.allowList) ? object.allowList.map(e => String(e)) : [],
      allowedPacketData: Array.isArray(object === null || object === void 0 ? void 0 : object.allowedPacketData) ? object.allowedPacketData.map(e => String(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    message.sourcePort !== undefined && (obj.sourcePort = message.sourcePort);
    message.sourceChannel !== undefined && (obj.sourceChannel = message.sourceChannel);
    if (message.spendLimit) {
      obj.spendLimit = message.spendLimit.map(e => e ? Coin.toJSON(e) : undefined);
    } else {
      obj.spendLimit = [];
    }
    if (message.allowList) {
      obj.allowList = message.allowList.map(e => e);
    } else {
      obj.allowList = [];
    }
    if (message.allowedPacketData) {
      obj.allowedPacketData = message.allowedPacketData.map(e => e);
    } else {
      obj.allowedPacketData = [];
    }
    return obj;
  },
  fromPartial(object) {
    var _object$sourcePort, _object$sourceChannel, _object$spendLimit, _object$allowList, _object$allowedPacket;
    const message = createBaseAllocation();
    message.sourcePort = (_object$sourcePort = object.sourcePort) !== null && _object$sourcePort !== void 0 ? _object$sourcePort : "";
    message.sourceChannel = (_object$sourceChannel = object.sourceChannel) !== null && _object$sourceChannel !== void 0 ? _object$sourceChannel : "";
    message.spendLimit = ((_object$spendLimit = object.spendLimit) === null || _object$spendLimit === void 0 ? void 0 : _object$spendLimit.map(e => Coin.fromPartial(e))) || [];
    message.allowList = ((_object$allowList = object.allowList) === null || _object$allowList === void 0 ? void 0 : _object$allowList.map(e => e)) || [];
    message.allowedPacketData = ((_object$allowedPacket = object.allowedPacketData) === null || _object$allowedPacket === void 0 ? void 0 : _object$allowedPacket.map(e => e)) || [];
    return message;
  }
};
function createBaseTransferAuthorization() {
  return {
    allocations: []
  };
}
export const TransferAuthorization = {
  encode(message, writer = _m0.Writer.create()) {
    for (const v of message.allocations) {
      Allocation.encode(v, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseTransferAuthorization();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.allocations.push(Allocation.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      allocations: Array.isArray(object === null || object === void 0 ? void 0 : object.allocations) ? object.allocations.map(e => Allocation.fromJSON(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.allocations) {
      obj.allocations = message.allocations.map(e => e ? Allocation.toJSON(e) : undefined);
    } else {
      obj.allocations = [];
    }
    return obj;
  },
  fromPartial(object) {
    var _object$allocations;
    const message = createBaseTransferAuthorization();
    message.allocations = ((_object$allocations = object.allocations) === null || _object$allocations === void 0 ? void 0 : _object$allocations.map(e => Allocation.fromPartial(e))) || [];
    return message;
  }
};