import { Params, FeedConfig, Transmission, EpochAndRound } from "./ocr";
import { Coin } from "../../../cosmos/base/v1beta1/coin";
import * as _m0 from "protobufjs/minimal";
import { Long } from "../../../helpers";
/** GenesisState defines the OCR module's genesis state. */

function createBaseGenesisState() {
  return {
    params: undefined,
    feedConfigs: [],
    latestEpochAndRounds: [],
    feedTransmissions: [],
    latestAggregatorRoundIds: [],
    rewardPools: [],
    feedObservationCounts: [],
    feedTransmissionCounts: [],
    pendingPayeeships: []
  };
}
export const GenesisState = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.params !== undefined) {
      Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    for (const v of message.feedConfigs) {
      FeedConfig.encode(v, writer.uint32(18).fork()).ldelim();
    }
    for (const v of message.latestEpochAndRounds) {
      FeedEpochAndRound.encode(v, writer.uint32(26).fork()).ldelim();
    }
    for (const v of message.feedTransmissions) {
      FeedTransmission.encode(v, writer.uint32(34).fork()).ldelim();
    }
    for (const v of message.latestAggregatorRoundIds) {
      FeedLatestAggregatorRoundIDs.encode(v, writer.uint32(42).fork()).ldelim();
    }
    for (const v of message.rewardPools) {
      RewardPool.encode(v, writer.uint32(50).fork()).ldelim();
    }
    for (const v of message.feedObservationCounts) {
      FeedCounts.encode(v, writer.uint32(58).fork()).ldelim();
    }
    for (const v of message.feedTransmissionCounts) {
      FeedCounts.encode(v, writer.uint32(66).fork()).ldelim();
    }
    for (const v of message.pendingPayeeships) {
      PendingPayeeship.encode(v, writer.uint32(74).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 = createBaseGenesisState();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.params = Params.decode(reader, reader.uint32());
          break;
        case 2:
          message.feedConfigs.push(FeedConfig.decode(reader, reader.uint32()));
          break;
        case 3:
          message.latestEpochAndRounds.push(FeedEpochAndRound.decode(reader, reader.uint32()));
          break;
        case 4:
          message.feedTransmissions.push(FeedTransmission.decode(reader, reader.uint32()));
          break;
        case 5:
          message.latestAggregatorRoundIds.push(FeedLatestAggregatorRoundIDs.decode(reader, reader.uint32()));
          break;
        case 6:
          message.rewardPools.push(RewardPool.decode(reader, reader.uint32()));
          break;
        case 7:
          message.feedObservationCounts.push(FeedCounts.decode(reader, reader.uint32()));
          break;
        case 8:
          message.feedTransmissionCounts.push(FeedCounts.decode(reader, reader.uint32()));
          break;
        case 9:
          message.pendingPayeeships.push(PendingPayeeship.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$feedConfigs, _object$latestEpochAn, _object$feedTransmiss, _object$latestAggrega, _object$rewardPools, _object$feedObservati, _object$feedTransmiss2, _object$pendingPayees;
    const message = createBaseGenesisState();
    message.params = object.params !== undefined && object.params !== null ? Params.fromPartial(object.params) : undefined;
    message.feedConfigs = ((_object$feedConfigs = object.feedConfigs) === null || _object$feedConfigs === void 0 ? void 0 : _object$feedConfigs.map(e => FeedConfig.fromPartial(e))) || [];
    message.latestEpochAndRounds = ((_object$latestEpochAn = object.latestEpochAndRounds) === null || _object$latestEpochAn === void 0 ? void 0 : _object$latestEpochAn.map(e => FeedEpochAndRound.fromPartial(e))) || [];
    message.feedTransmissions = ((_object$feedTransmiss = object.feedTransmissions) === null || _object$feedTransmiss === void 0 ? void 0 : _object$feedTransmiss.map(e => FeedTransmission.fromPartial(e))) || [];
    message.latestAggregatorRoundIds = ((_object$latestAggrega = object.latestAggregatorRoundIds) === null || _object$latestAggrega === void 0 ? void 0 : _object$latestAggrega.map(e => FeedLatestAggregatorRoundIDs.fromPartial(e))) || [];
    message.rewardPools = ((_object$rewardPools = object.rewardPools) === null || _object$rewardPools === void 0 ? void 0 : _object$rewardPools.map(e => RewardPool.fromPartial(e))) || [];
    message.feedObservationCounts = ((_object$feedObservati = object.feedObservationCounts) === null || _object$feedObservati === void 0 ? void 0 : _object$feedObservati.map(e => FeedCounts.fromPartial(e))) || [];
    message.feedTransmissionCounts = ((_object$feedTransmiss2 = object.feedTransmissionCounts) === null || _object$feedTransmiss2 === void 0 ? void 0 : _object$feedTransmiss2.map(e => FeedCounts.fromPartial(e))) || [];
    message.pendingPayeeships = ((_object$pendingPayees = object.pendingPayeeships) === null || _object$pendingPayees === void 0 ? void 0 : _object$pendingPayees.map(e => PendingPayeeship.fromPartial(e))) || [];
    return message;
  }
};
function createBaseFeedTransmission() {
  return {
    feedId: "",
    transmission: undefined
  };
}
export const FeedTransmission = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.feedId !== "") {
      writer.uint32(10).string(message.feedId);
    }
    if (message.transmission !== undefined) {
      Transmission.encode(message.transmission, writer.uint32(18).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 = createBaseFeedTransmission();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.feedId = reader.string();
          break;
        case 2:
          message.transmission = Transmission.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$feedId;
    const message = createBaseFeedTransmission();
    message.feedId = (_object$feedId = object.feedId) !== null && _object$feedId !== void 0 ? _object$feedId : "";
    message.transmission = object.transmission !== undefined && object.transmission !== null ? Transmission.fromPartial(object.transmission) : undefined;
    return message;
  }
};
function createBaseFeedEpochAndRound() {
  return {
    feedId: "",
    epochAndRound: undefined
  };
}
export const FeedEpochAndRound = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.feedId !== "") {
      writer.uint32(10).string(message.feedId);
    }
    if (message.epochAndRound !== undefined) {
      EpochAndRound.encode(message.epochAndRound, writer.uint32(18).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 = createBaseFeedEpochAndRound();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.feedId = reader.string();
          break;
        case 2:
          message.epochAndRound = EpochAndRound.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$feedId2;
    const message = createBaseFeedEpochAndRound();
    message.feedId = (_object$feedId2 = object.feedId) !== null && _object$feedId2 !== void 0 ? _object$feedId2 : "";
    message.epochAndRound = object.epochAndRound !== undefined && object.epochAndRound !== null ? EpochAndRound.fromPartial(object.epochAndRound) : undefined;
    return message;
  }
};
function createBaseFeedLatestAggregatorRoundIDs() {
  return {
    feedId: "",
    aggregatorRoundId: Long.UZERO
  };
}
export const FeedLatestAggregatorRoundIDs = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.feedId !== "") {
      writer.uint32(10).string(message.feedId);
    }
    if (!message.aggregatorRoundId.isZero()) {
      writer.uint32(16).uint64(message.aggregatorRoundId);
    }
    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 = createBaseFeedLatestAggregatorRoundIDs();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.feedId = reader.string();
          break;
        case 2:
          message.aggregatorRoundId = reader.uint64();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$feedId3;
    const message = createBaseFeedLatestAggregatorRoundIDs();
    message.feedId = (_object$feedId3 = object.feedId) !== null && _object$feedId3 !== void 0 ? _object$feedId3 : "";
    message.aggregatorRoundId = object.aggregatorRoundId !== undefined && object.aggregatorRoundId !== null ? Long.fromValue(object.aggregatorRoundId) : Long.UZERO;
    return message;
  }
};
function createBaseRewardPool() {
  return {
    feedId: "",
    amount: undefined
  };
}
export const RewardPool = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.feedId !== "") {
      writer.uint32(10).string(message.feedId);
    }
    if (message.amount !== undefined) {
      Coin.encode(message.amount, writer.uint32(18).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 = createBaseRewardPool();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.feedId = reader.string();
          break;
        case 2:
          message.amount = Coin.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$feedId4;
    const message = createBaseRewardPool();
    message.feedId = (_object$feedId4 = object.feedId) !== null && _object$feedId4 !== void 0 ? _object$feedId4 : "";
    message.amount = object.amount !== undefined && object.amount !== null ? Coin.fromPartial(object.amount) : undefined;
    return message;
  }
};
function createBaseFeedCounts() {
  return {
    feedId: "",
    counts: []
  };
}
export const FeedCounts = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.feedId !== "") {
      writer.uint32(10).string(message.feedId);
    }
    for (const v of message.counts) {
      Count.encode(v, writer.uint32(18).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 = createBaseFeedCounts();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.feedId = reader.string();
          break;
        case 2:
          message.counts.push(Count.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$feedId5, _object$counts;
    const message = createBaseFeedCounts();
    message.feedId = (_object$feedId5 = object.feedId) !== null && _object$feedId5 !== void 0 ? _object$feedId5 : "";
    message.counts = ((_object$counts = object.counts) === null || _object$counts === void 0 ? void 0 : _object$counts.map(e => Count.fromPartial(e))) || [];
    return message;
  }
};
function createBaseCount() {
  return {
    address: "",
    count: Long.UZERO
  };
}
export const Count = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.address !== "") {
      writer.uint32(10).string(message.address);
    }
    if (!message.count.isZero()) {
      writer.uint32(16).uint64(message.count);
    }
    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 = createBaseCount();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.address = reader.string();
          break;
        case 2:
          message.count = reader.uint64();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$address;
    const message = createBaseCount();
    message.address = (_object$address = object.address) !== null && _object$address !== void 0 ? _object$address : "";
    message.count = object.count !== undefined && object.count !== null ? Long.fromValue(object.count) : Long.UZERO;
    return message;
  }
};
function createBasePendingPayeeship() {
  return {
    feedId: "",
    transmitter: "",
    proposedPayee: ""
  };
}
export const PendingPayeeship = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.feedId !== "") {
      writer.uint32(10).string(message.feedId);
    }
    if (message.transmitter !== "") {
      writer.uint32(18).string(message.transmitter);
    }
    if (message.proposedPayee !== "") {
      writer.uint32(26).string(message.proposedPayee);
    }
    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 = createBasePendingPayeeship();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.feedId = reader.string();
          break;
        case 2:
          message.transmitter = reader.string();
          break;
        case 3:
          message.proposedPayee = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$feedId6, _object$transmitter, _object$proposedPayee;
    const message = createBasePendingPayeeship();
    message.feedId = (_object$feedId6 = object.feedId) !== null && _object$feedId6 !== void 0 ? _object$feedId6 : "";
    message.transmitter = (_object$transmitter = object.transmitter) !== null && _object$transmitter !== void 0 ? _object$transmitter : "";
    message.proposedPayee = (_object$proposedPayee = object.proposedPayee) !== null && _object$proposedPayee !== void 0 ? _object$proposedPayee : "";
    return message;
  }
};