import { Timestamp } from "../google/protobuf/timestamp";
import { BinaryWriter } from "../binary";
import { Decimal } from "@cosmjs/math";
import { isSet, fromJsonTimestamp } from "../helpers";

/** Params defines the parameters for the module. */

/** Params defines the parameters for the module. */

/** Params defines the parameters for the module. */

function createBaseDistributionProportion() {
  return {
    proportion: "",
    address: ""
  };
}
export const DistributionProportion = {
  typeUrl: "/gitopia.gitopia.gitopia.DistributionProportion",
  encode(message, writer = BinaryWriter.create()) {
    if (message.proportion !== "") {
      writer.uint32(10).string(Decimal.fromUserInput(message.proportion, 18).atomics);
    }
    if (message.address !== "") {
      writer.uint32(18).string(message.address);
    }
    return writer;
  },
  fromJSON(object) {
    return {
      proportion: isSet(object.proportion) ? String(object.proportion) : "",
      address: isSet(object.address) ? String(object.address) : ""
    };
  },
  fromPartial(object) {
    var _object$proportion, _object$address;
    const message = createBaseDistributionProportion();
    message.proportion = (_object$proportion = object.proportion) !== null && _object$proportion !== void 0 ? _object$proportion : "";
    message.address = (_object$address = object.address) !== null && _object$address !== void 0 ? _object$address : "";
    return message;
  },
  fromAmino(object) {
    const message = createBaseDistributionProportion();
    if (object.proportion !== undefined && object.proportion !== null) {
      message.proportion = object.proportion;
    }
    if (object.address !== undefined && object.address !== null) {
      message.address = object.address;
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.proportion = message.proportion === "" ? undefined : message.proportion;
    obj.address = message.address === "" ? undefined : message.address;
    return obj;
  },
  fromAminoMsg(object) {
    return DistributionProportion.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return DistributionProportion.decode(message.value);
  },
  toProto(message) {
    return DistributionProportion.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.gitopia.DistributionProportion",
      value: DistributionProportion.encode(message).finish()
    };
  }
};
function createBasePoolProportions() {
  return {
    ecosystem: undefined,
    team: undefined,
    platform: undefined
  };
}
export const PoolProportions = {
  typeUrl: "/gitopia.gitopia.gitopia.PoolProportions",
  encode(message, writer = BinaryWriter.create()) {
    if (message.ecosystem !== undefined) {
      DistributionProportion.encode(message.ecosystem, writer.uint32(10).fork()).ldelim();
    }
    if (message.team !== undefined) {
      DistributionProportion.encode(message.team, writer.uint32(18).fork()).ldelim();
    }
    if (message.platform !== undefined) {
      DistributionProportion.encode(message.platform, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      ecosystem: isSet(object.ecosystem) ? DistributionProportion.fromJSON(object.ecosystem) : undefined,
      team: isSet(object.team) ? DistributionProportion.fromJSON(object.team) : undefined,
      platform: isSet(object.platform) ? DistributionProportion.fromJSON(object.platform) : undefined
    };
  },
  fromPartial(object) {
    const message = createBasePoolProportions();
    message.ecosystem = object.ecosystem !== undefined && object.ecosystem !== null ? DistributionProportion.fromPartial(object.ecosystem) : undefined;
    message.team = object.team !== undefined && object.team !== null ? DistributionProportion.fromPartial(object.team) : undefined;
    message.platform = object.platform !== undefined && object.platform !== null ? DistributionProportion.fromPartial(object.platform) : undefined;
    return message;
  },
  fromAmino(object) {
    const message = createBasePoolProportions();
    if (object.ecosystem !== undefined && object.ecosystem !== null) {
      message.ecosystem = DistributionProportion.fromAmino(object.ecosystem);
    }
    if (object.team !== undefined && object.team !== null) {
      message.team = DistributionProportion.fromAmino(object.team);
    }
    if (object.platform !== undefined && object.platform !== null) {
      message.platform = DistributionProportion.fromAmino(object.platform);
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.ecosystem = message.ecosystem ? DistributionProportion.toAmino(message.ecosystem) : undefined;
    obj.team = message.team ? DistributionProportion.toAmino(message.team) : undefined;
    obj.platform = message.platform ? DistributionProportion.toAmino(message.platform) : undefined;
    return obj;
  },
  fromAminoMsg(object) {
    return PoolProportions.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return PoolProportions.decode(message.value);
  },
  toProto(message) {
    return PoolProportions.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.gitopia.PoolProportions",
      value: PoolProportions.encode(message).finish()
    };
  }
};
function createBaseParams() {
  return {
    nextInflationTime: Timestamp.fromPartial({}),
    poolProportions: PoolProportions.fromPartial({}),
    teamProportions: [],
    genesisTime: Timestamp.fromPartial({}),
    gitServer: "",
    storageProvider: ""
  };
}
export const Params = {
  typeUrl: "/gitopia.gitopia.gitopia.Params",
  encode(message, writer = BinaryWriter.create()) {
    if (message.nextInflationTime !== undefined) {
      Timestamp.encode(message.nextInflationTime, writer.uint32(10).fork()).ldelim();
    }
    if (message.poolProportions !== undefined) {
      PoolProportions.encode(message.poolProportions, writer.uint32(18).fork()).ldelim();
    }
    for (const v of message.teamProportions) {
      DistributionProportion.encode(v, writer.uint32(26).fork()).ldelim();
    }
    if (message.genesisTime !== undefined) {
      Timestamp.encode(message.genesisTime, writer.uint32(34).fork()).ldelim();
    }
    if (message.gitServer !== "") {
      writer.uint32(42).string(message.gitServer);
    }
    if (message.storageProvider !== "") {
      writer.uint32(50).string(message.storageProvider);
    }
    return writer;
  },
  fromJSON(object) {
    return {
      nextInflationTime: isSet(object.nextInflationTime) ? fromJsonTimestamp(object.nextInflationTime) : undefined,
      poolProportions: isSet(object.poolProportions) ? PoolProportions.fromJSON(object.poolProportions) : undefined,
      teamProportions: Array.isArray(object === null || object === void 0 ? void 0 : object.teamProportions) ? object.teamProportions.map(e => DistributionProportion.fromJSON(e)) : [],
      genesisTime: isSet(object.genesisTime) ? fromJsonTimestamp(object.genesisTime) : undefined,
      gitServer: isSet(object.gitServer) ? String(object.gitServer) : "",
      storageProvider: isSet(object.storageProvider) ? String(object.storageProvider) : ""
    };
  },
  fromPartial(object) {
    var _object$teamProportio, _object$gitServer, _object$storageProvid;
    const message = createBaseParams();
    message.nextInflationTime = object.nextInflationTime !== undefined && object.nextInflationTime !== null ? Timestamp.fromPartial(object.nextInflationTime) : undefined;
    message.poolProportions = object.poolProportions !== undefined && object.poolProportions !== null ? PoolProportions.fromPartial(object.poolProportions) : undefined;
    message.teamProportions = ((_object$teamProportio = object.teamProportions) === null || _object$teamProportio === void 0 ? void 0 : _object$teamProportio.map(e => DistributionProportion.fromPartial(e))) || [];
    message.genesisTime = object.genesisTime !== undefined && object.genesisTime !== null ? Timestamp.fromPartial(object.genesisTime) : undefined;
    message.gitServer = (_object$gitServer = object.gitServer) !== null && _object$gitServer !== void 0 ? _object$gitServer : "";
    message.storageProvider = (_object$storageProvid = object.storageProvider) !== null && _object$storageProvid !== void 0 ? _object$storageProvid : "";
    return message;
  },
  fromAmino(object) {
    var _object$team_proporti;
    const message = createBaseParams();
    if (object.next_inflation_time !== undefined && object.next_inflation_time !== null) {
      message.nextInflationTime = Timestamp.fromAmino(object.next_inflation_time);
    }
    if (object.pool_proportions !== undefined && object.pool_proportions !== null) {
      message.poolProportions = PoolProportions.fromAmino(object.pool_proportions);
    }
    message.teamProportions = ((_object$team_proporti = object.team_proportions) === null || _object$team_proporti === void 0 ? void 0 : _object$team_proporti.map(e => DistributionProportion.fromAmino(e))) || [];
    if (object.genesis_time !== undefined && object.genesis_time !== null) {
      message.genesisTime = Timestamp.fromAmino(object.genesis_time);
    }
    if (object.git_server !== undefined && object.git_server !== null) {
      message.gitServer = object.git_server;
    }
    if (object.storage_provider !== undefined && object.storage_provider !== null) {
      message.storageProvider = object.storage_provider;
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.next_inflation_time = message.nextInflationTime ? Timestamp.toAmino(message.nextInflationTime) : undefined;
    obj.pool_proportions = message.poolProportions ? PoolProportions.toAmino(message.poolProportions) : undefined;
    if (message.teamProportions) {
      obj.team_proportions = message.teamProportions.map(e => e ? DistributionProportion.toAmino(e) : undefined);
    } else {
      obj.team_proportions = message.teamProportions;
    }
    obj.genesis_time = message.genesisTime ? Timestamp.toAmino(message.genesisTime) : undefined;
    obj.git_server = message.gitServer === "" ? undefined : message.gitServer;
    obj.storage_provider = message.storageProvider === "" ? undefined : message.storageProvider;
    return obj;
  },
  fromAminoMsg(object) {
    return Params.fromAmino(object.value);
  },
  fromProtoMsg(message) {
    return Params.decode(message.value);
  },
  toProto(message) {
    return Params.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.gitopia.Params",
      value: Params.encode(message).finish()
    };
  }
};