import { BinaryWriter } from "../../../binary";
import { isSet } from "../../../helpers";
/** ModuleDescriptor describes an app module. */

/** ModuleDescriptor describes an app module. */

/** ModuleDescriptor describes an app module. */

/** PackageReference is a reference to a protobuf package used by a module. */

/** PackageReference is a reference to a protobuf package used by a module. */

/** PackageReference is a reference to a protobuf package used by a module. */

/**
 * MigrateFromInfo is information on a module version that a newer module
 * can migrate from.
 */

/**
 * MigrateFromInfo is information on a module version that a newer module
 * can migrate from.
 */

/**
 * MigrateFromInfo is information on a module version that a newer module
 * can migrate from.
 */

function createBaseModuleDescriptor() {
  return {
    goImport: "",
    usePackage: [],
    canMigrateFrom: []
  };
}
export const ModuleDescriptor = {
  typeUrl: "/cosmos.app.v1alpha1.ModuleDescriptor",
  encode(message, writer = BinaryWriter.create()) {
    if (message.goImport !== "") {
      writer.uint32(10).string(message.goImport);
    }
    for (const v of message.usePackage) {
      PackageReference.encode(v, writer.uint32(18).fork()).ldelim();
    }
    for (const v of message.canMigrateFrom) {
      MigrateFromInfo.encode(v, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  fromJSON(object) {
    return {
      goImport: isSet(object.goImport) ? String(object.goImport) : "",
      usePackage: Array.isArray(object === null || object === void 0 ? void 0 : object.usePackage) ? object.usePackage.map(e => PackageReference.fromJSON(e)) : [],
      canMigrateFrom: Array.isArray(object === null || object === void 0 ? void 0 : object.canMigrateFrom) ? object.canMigrateFrom.map(e => MigrateFromInfo.fromJSON(e)) : []
    };
  },
  fromPartial(object) {
    var _object$goImport, _object$usePackage, _object$canMigrateFro;
    const message = createBaseModuleDescriptor();
    message.goImport = (_object$goImport = object.goImport) !== null && _object$goImport !== void 0 ? _object$goImport : "";
    message.usePackage = ((_object$usePackage = object.usePackage) === null || _object$usePackage === void 0 ? void 0 : _object$usePackage.map(e => PackageReference.fromPartial(e))) || [];
    message.canMigrateFrom = ((_object$canMigrateFro = object.canMigrateFrom) === null || _object$canMigrateFro === void 0 ? void 0 : _object$canMigrateFro.map(e => MigrateFromInfo.fromPartial(e))) || [];
    return message;
  },
  fromAmino(object) {
    var _object$use_package, _object$can_migrate_f;
    const message = createBaseModuleDescriptor();
    if (object.go_import !== undefined && object.go_import !== null) {
      message.goImport = object.go_import;
    }
    message.usePackage = ((_object$use_package = object.use_package) === null || _object$use_package === void 0 ? void 0 : _object$use_package.map(e => PackageReference.fromAmino(e))) || [];
    message.canMigrateFrom = ((_object$can_migrate_f = object.can_migrate_from) === null || _object$can_migrate_f === void 0 ? void 0 : _object$can_migrate_f.map(e => MigrateFromInfo.fromAmino(e))) || [];
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.go_import = message.goImport === "" ? undefined : message.goImport;
    if (message.usePackage) {
      obj.use_package = message.usePackage.map(e => e ? PackageReference.toAmino(e) : undefined);
    } else {
      obj.use_package = message.usePackage;
    }
    if (message.canMigrateFrom) {
      obj.can_migrate_from = message.canMigrateFrom.map(e => e ? MigrateFromInfo.toAmino(e) : undefined);
    } else {
      obj.can_migrate_from = message.canMigrateFrom;
    }
    return obj;
  },
  fromAminoMsg(object) {
    return ModuleDescriptor.fromAmino(object.value);
  },
  toAminoMsg(message) {
    return {
      type: "cosmos-sdk/ModuleDescriptor",
      value: ModuleDescriptor.toAmino(message)
    };
  },
  fromProtoMsg(message) {
    return ModuleDescriptor.decode(message.value);
  },
  toProto(message) {
    return ModuleDescriptor.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.app.v1alpha1.ModuleDescriptor",
      value: ModuleDescriptor.encode(message).finish()
    };
  }
};
function createBasePackageReference() {
  return {
    name: "",
    revision: 0
  };
}
export const PackageReference = {
  typeUrl: "/cosmos.app.v1alpha1.PackageReference",
  encode(message, writer = BinaryWriter.create()) {
    if (message.name !== "") {
      writer.uint32(10).string(message.name);
    }
    if (message.revision !== 0) {
      writer.uint32(16).uint32(message.revision);
    }
    return writer;
  },
  fromJSON(object) {
    return {
      name: isSet(object.name) ? String(object.name) : "",
      revision: isSet(object.revision) ? Number(object.revision) : 0
    };
  },
  fromPartial(object) {
    var _object$name, _object$revision;
    const message = createBasePackageReference();
    message.name = (_object$name = object.name) !== null && _object$name !== void 0 ? _object$name : "";
    message.revision = (_object$revision = object.revision) !== null && _object$revision !== void 0 ? _object$revision : 0;
    return message;
  },
  fromAmino(object) {
    const message = createBasePackageReference();
    if (object.name !== undefined && object.name !== null) {
      message.name = object.name;
    }
    if (object.revision !== undefined && object.revision !== null) {
      message.revision = object.revision;
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.name = message.name === "" ? undefined : message.name;
    obj.revision = message.revision === 0 ? undefined : message.revision;
    return obj;
  },
  fromAminoMsg(object) {
    return PackageReference.fromAmino(object.value);
  },
  toAminoMsg(message) {
    return {
      type: "cosmos-sdk/PackageReference",
      value: PackageReference.toAmino(message)
    };
  },
  fromProtoMsg(message) {
    return PackageReference.decode(message.value);
  },
  toProto(message) {
    return PackageReference.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.app.v1alpha1.PackageReference",
      value: PackageReference.encode(message).finish()
    };
  }
};
function createBaseMigrateFromInfo() {
  return {
    module: ""
  };
}
export const MigrateFromInfo = {
  typeUrl: "/cosmos.app.v1alpha1.MigrateFromInfo",
  encode(message, writer = BinaryWriter.create()) {
    if (message.module !== "") {
      writer.uint32(10).string(message.module);
    }
    return writer;
  },
  fromJSON(object) {
    return {
      module: isSet(object.module) ? String(object.module) : ""
    };
  },
  fromPartial(object) {
    var _object$module;
    const message = createBaseMigrateFromInfo();
    message.module = (_object$module = object.module) !== null && _object$module !== void 0 ? _object$module : "";
    return message;
  },
  fromAmino(object) {
    const message = createBaseMigrateFromInfo();
    if (object.module !== undefined && object.module !== null) {
      message.module = object.module;
    }
    return message;
  },
  toAmino(message) {
    const obj = {};
    obj.module = message.module === "" ? undefined : message.module;
    return obj;
  },
  fromAminoMsg(object) {
    return MigrateFromInfo.fromAmino(object.value);
  },
  toAminoMsg(message) {
    return {
      type: "cosmos-sdk/MigrateFromInfo",
      value: MigrateFromInfo.toAmino(message)
    };
  },
  fromProtoMsg(message) {
    return MigrateFromInfo.decode(message.value);
  },
  toProto(message) {
    return MigrateFromInfo.encode(message).finish();
  },
  toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.app.v1alpha1.MigrateFromInfo",
      value: MigrateFromInfo.encode(message).finish()
    };
  }
};