// DO NOT EDIT.
//
// Generated by the Swift generator plugin for the protocol buffer compiler.
// Source: tendermint/crypto/keys.proto
//
// For information on using the generated types, please see the documentation:
//   https://github.com/apple/swift-protobuf/

import Foundation
import SwiftProtobuf

// If the compiler emits an error on this type, it is because this file
// was generated by a version of the `protoc` Swift plug-in that is
// incompatible with the version of SwiftProtobuf to which you are linking.
// Please ensure that you are building against the same version of the API
// that was used to generate this file.
fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
  struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
  typealias Version = _2
}

/// PublicKey defines the keys available for use with Tendermint Validators
struct Tendermint_Crypto_PublicKey {
  // SwiftProtobuf.Message conformance is added in an extension below. See the
  // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
  // methods supported on all messages.

  var sum: Tendermint_Crypto_PublicKey.OneOf_Sum? = nil

  var ed25519: Data {
    get {
      if case .ed25519(let v)? = sum {return v}
      return SwiftProtobuf.Internal.emptyData
    }
    set {sum = .ed25519(newValue)}
  }

  var secp256K1: Data {
    get {
      if case .secp256K1(let v)? = sum {return v}
      return SwiftProtobuf.Internal.emptyData
    }
    set {sum = .secp256K1(newValue)}
  }

  var unknownFields = SwiftProtobuf.UnknownStorage()

  enum OneOf_Sum: Equatable {
    case ed25519(Data)
    case secp256K1(Data)

  #if !swift(>=4.1)
    static func ==(lhs: Tendermint_Crypto_PublicKey.OneOf_Sum, rhs: Tendermint_Crypto_PublicKey.OneOf_Sum) -> Bool {
      switch (lhs, rhs) {
      case (.ed25519(let l), .ed25519(let r)): return l == r
      case (.secp256K1(let l), .secp256K1(let r)): return l == r
      default: return false
      }
    }
  #endif
  }

  init() {}
}

// MARK: - Code below here is support for the SwiftProtobuf runtime.

fileprivate let _protobuf_package = "tendermint.crypto"

extension Tendermint_Crypto_PublicKey: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
  static let protoMessageName: String = _protobuf_package + ".PublicKey"
  static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
    1: .same(proto: "ed25519"),
    2: .same(proto: "secp256k1"),
  ]

  mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
    while let fieldNumber = try decoder.nextFieldNumber() {
      switch fieldNumber {
      case 1:
        if self.sum != nil {try decoder.handleConflictingOneOf()}
        var v: Data?
        try decoder.decodeSingularBytesField(value: &v)
        if let v = v {self.sum = .ed25519(v)}
      case 2:
        if self.sum != nil {try decoder.handleConflictingOneOf()}
        var v: Data?
        try decoder.decodeSingularBytesField(value: &v)
        if let v = v {self.sum = .secp256K1(v)}
      default: break
      }
    }
  }

  func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
    switch self.sum {
    case .ed25519(let v)?:
      try visitor.visitSingularBytesField(value: v, fieldNumber: 1)
    case .secp256K1(let v)?:
      try visitor.visitSingularBytesField(value: v, fieldNumber: 2)
    case nil: break
    }
    try unknownFields.traverse(visitor: &visitor)
  }

  static func ==(lhs: Tendermint_Crypto_PublicKey, rhs: Tendermint_Crypto_PublicKey) -> Bool {
    if lhs.sum != rhs.sum {return false}
    if lhs.unknownFields != rhs.unknownFields {return false}
    return true
  }
}
