import { BinaryWriter } from "../../../binary";
import { isSet } from "../../../helpers";
/** ParameterChangeProposal defines a proposal to change one or more parameters. */

/** ParameterChangeProposal defines a proposal to change one or more parameters. */

/** ParameterChangeProposal defines a proposal to change one or more parameters. */

/**
 * ParamChange defines an individual parameter change, for use in
 * ParameterChangeProposal.
 */

/**
 * ParamChange defines an individual parameter change, for use in
 * ParameterChangeProposal.
 */

/**
 * ParamChange defines an individual parameter change, for use in
 * ParameterChangeProposal.
 */

function createBaseParameterChangeProposal() {
  return {
    $typeUrl: "/cosmos.params.v1beta1.ParameterChangeProposal",
    title: "",
    description: "",
    changes: []
  };
}
export const ParameterChangeProposal = {
  typeUrl: "/cosmos.params.v1beta1.ParameterChangeProposal",
  encode(message, writer = BinaryWriter.create()) {
    if (message.title !== "") {
      writer.uint32(10).string(message.title);
    }
    if (message.description !== "") {
      writer.uint32(18).string(message.description);
    }
    for (const v of message.changes) {
      ParamChange.encode(v, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      title: isSet(object.title) ? String(object.title) : "",
      description: isSet(object.description) ? String(object.description) : "",
      changes: Array.isArray(object === null || object === void 0 ? void 0 : object.changes) ? object.changes.map(e => ParamChange.fromJSON(e)) : []
    };
  },
  fromPartial(object) {
    var _object$title, _object$description, _object$changes;
    const message = createBaseParameterChangeProposal();
    message.title = (_object$title = object.title) !== null && _object$title !== void 0 ? _object$title : "";
    message.description = (_object$description = object.description) !== null && _object$description !== void 0 ? _object$description : "";
    message.changes = ((_object$changes = object.changes) === null || _object$changes === void 0 ? void 0 : _object$changes.map(e => ParamChange.fromPartial(e))) || [];
    return message;
  },
  fromAmino(object) {
    var _object$changes2;
    const message = createBaseParameterChangeProposal();
    if (object.title !== undefined && object.title !== null) {
      message.title = object.title;
    }
    if (object.description !== undefined && object.description !== null) {
      message.description = object.description;
    }
    message.changes = ((_object$changes2 = object.changes) === null || _object$changes2 === void 0 ? void 0 : _object$changes2.map(e => ParamChange.fromAmino(e))) || [];
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.title = message.title === "" ? undefined : message.title;
    obj.description = message.description === "" ? undefined : message.description;
    if (message.changes) {
      obj.changes = message.changes.map(e => e ? ParamChange.toAmino(e) : undefined);
    } else {
      obj.changes = message.changes;
    }
    return obj;
  },
  fromAminoMsg(object) {
    return ParameterChangeProposal.fromAmino(object.value);
  },
  toAminoMsg(message) {
    return {
      type: "cosmos-sdk/ParameterChangeProposal",
      value: ParameterChangeProposal.toAmino(message)
    };
  },
  fromProtoMsg(message) {
    return ParameterChangeProposal.decode(message.value);
  },
  toProto(message) {
    return ParameterChangeProposal.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.params.v1beta1.ParameterChangeProposal",
      value: ParameterChangeProposal.encode(message).finish()
    };
  }
};
function createBaseParamChange() {
  return {
    subspace: "",
    key: "",
    value: ""
  };
}
export const ParamChange = {
  typeUrl: "/cosmos.params.v1beta1.ParamChange",
  encode(message, writer = BinaryWriter.create()) {
    if (message.subspace !== "") {
      writer.uint32(10).string(message.subspace);
    }
    if (message.key !== "") {
      writer.uint32(18).string(message.key);
    }
    if (message.value !== "") {
      writer.uint32(26).string(message.value);
    }
    return writer;
  },
  fromJSON(object) {
    return {
      subspace: isSet(object.subspace) ? String(object.subspace) : "",
      key: isSet(object.key) ? String(object.key) : "",
      value: isSet(object.value) ? String(object.value) : ""
    };
  },
  fromPartial(object) {
    var _object$subspace, _object$key, _object$value;
    const message = createBaseParamChange();
    message.subspace = (_object$subspace = object.subspace) !== null && _object$subspace !== void 0 ? _object$subspace : "";
    message.key = (_object$key = object.key) !== null && _object$key !== void 0 ? _object$key : "";
    message.value = (_object$value = object.value) !== null && _object$value !== void 0 ? _object$value : "";
    return message;
  },
  fromAmino(object) {
    const message = createBaseParamChange();
    if (object.subspace !== undefined && object.subspace !== null) {
      message.subspace = object.subspace;
    }
    if (object.key !== undefined && object.key !== null) {
      message.key = object.key;
    }
    if (object.value !== undefined && object.value !== null) {
      message.value = object.value;
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.subspace = message.subspace === "" ? undefined : message.subspace;
    obj.key = message.key === "" ? undefined : message.key;
    obj.value = message.value === "" ? undefined : message.value;
    return obj;
  },
  fromAminoMsg(object) {
    return ParamChange.fromAmino(object.value);
  },
  toAminoMsg(message) {
    return {
      type: "cosmos-sdk/ParamChange",
      value: ParamChange.toAmino(message)
    };
  },
  fromProtoMsg(message) {
    return ParamChange.decode(message.value);
  },
  toProto(message) {
    return ParamChange.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.params.v1beta1.ParamChange",
      value: ParamChange.encode(message).finish()
    };
  }
};