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

///*
/// Specifies top-level records related to the generic concept of a user's government-issued identification. These
/// records are specified for a user if we have ID on file for them, regardless of the type/status of the ID itself.

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 your 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
}

/// Enumerates supported types of user-provided, government-issued ID.
public enum Bloombox_Identity_IDType: SwiftProtobuf.Enum {
  public typealias RawValue = Int

  /// United States Driver's License, issued by a U.S. state government.
  case usdl // = 0

  /// National passport, issued by a nation-state.
  case passport // = 1
  case UNRECOGNIZED(Int)

  public init() {
    self = .usdl
  }

  public init?(rawValue: Int) {
    switch rawValue {
    case 0: self = .usdl
    case 1: self = .passport
    default: self = .UNRECOGNIZED(rawValue)
    }
  }

  public var rawValue: Int {
    switch self {
    case .usdl: return 0
    case .passport: return 1
    case .UNRECOGNIZED(let i): return i
    }
  }

}

#if swift(>=4.2)

extension Bloombox_Identity_IDType: CaseIterable {
  // The compiler won't synthesize support with the UNRECOGNIZED case.
  public static var allCases: [Bloombox_Identity_IDType] = [
    .usdl,
    .passport,
  ]
}

#endif  // swift(>=4.2)

/// Reference to a government-issued ID.
public struct Bloombox_Identity_IDReference {
  // 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.

  /// Type of ID we're specifying.
  public var type: Bloombox_Identity_IDType {
    get {return _storage._type}
    set {_uniqueStorage()._type = newValue}
  }

  /// Expiration date for this document.
  public var expireDate: Opencannabis_Temporal_Date {
    get {return _storage._expireDate ?? Opencannabis_Temporal_Date()}
    set {_uniqueStorage()._expireDate = newValue}
  }
  /// Returns true if `expireDate` has been explicitly set.
  public var hasExpireDate: Bool {return _storage._expireDate != nil}
  /// Clears the value of `expireDate`. Subsequent reads from it will return its default value.
  public mutating func clearExpireDate() {_uniqueStorage()._expireDate = nil}

  /// Birth date listed on this document.
  public var birthDate: Opencannabis_Temporal_Date {
    get {return _storage._birthDate ?? Opencannabis_Temporal_Date()}
    set {_uniqueStorage()._birthDate = newValue}
  }
  /// Returns true if `birthDate` has been explicitly set.
  public var hasBirthDate: Bool {return _storage._birthDate != nil}
  /// Clears the value of `birthDate`. Subsequent reads from it will return its default value.
  public mutating func clearBirthDate() {_uniqueStorage()._birthDate = nil}

  public var document: OneOf_Document? {
    get {return _storage._document}
    set {_uniqueStorage()._document = newValue}
  }

  /// United States Driver's License.
  public var license: Bloombox_Identity_Ids_USDLReference {
    get {
      if case .license(let v)? = _storage._document {return v}
      return Bloombox_Identity_Ids_USDLReference()
    }
    set {_uniqueStorage()._document = .license(newValue)}
  }

  /// National passport.
  public var passport: Bloombox_Identity_Ids_PassportReference {
    get {
      if case .passport(let v)? = _storage._document {return v}
      return Bloombox_Identity_Ids_PassportReference()
    }
    set {_uniqueStorage()._document = .passport(newValue)}
  }

  public var unknownFields = SwiftProtobuf.UnknownStorage()

  public enum OneOf_Document: Equatable {
    /// United States Driver's License.
    case license(Bloombox_Identity_Ids_USDLReference)
    /// National passport.
    case passport(Bloombox_Identity_Ids_PassportReference)

  #if !swift(>=4.1)
    public static func ==(lhs: Bloombox_Identity_IDReference.OneOf_Document, rhs: Bloombox_Identity_IDReference.OneOf_Document) -> Bool {
      switch (lhs, rhs) {
      case (.license(let l), .license(let r)): return l == r
      case (.passport(let l), .passport(let r)): return l == r
      default: return false
      }
    }
  #endif
  }

  public init() {}

  fileprivate var _storage = _StorageClass.defaultInstance
}

/// Specifies an object for expressing a user's government ID information.
public struct Bloombox_Identity_ID {
  // 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.

  /// Type of ID we're specifying.
  public var type: Bloombox_Identity_IDType {
    get {return _storage._type}
    set {_uniqueStorage()._type = newValue}
  }

  /// ID number or string identifying this identity document.
  public var id: String {
    get {return _storage._id}
    set {_uniqueStorage()._id = newValue}
  }

  /// Expiration date for this document.
  public var expireDate: Opencannabis_Temporal_Date {
    get {return _storage._expireDate ?? Opencannabis_Temporal_Date()}
    set {_uniqueStorage()._expireDate = newValue}
  }
  /// Returns true if `expireDate` has been explicitly set.
  public var hasExpireDate: Bool {return _storage._expireDate != nil}
  /// Clears the value of `expireDate`. Subsequent reads from it will return its default value.
  public mutating func clearExpireDate() {_uniqueStorage()._expireDate = nil}

  /// Birth date listed on this document.
  public var birthDate: Opencannabis_Temporal_Date {
    get {return _storage._birthDate ?? Opencannabis_Temporal_Date()}
    set {_uniqueStorage()._birthDate = newValue}
  }
  /// Returns true if `birthDate` has been explicitly set.
  public var hasBirthDate: Bool {return _storage._birthDate != nil}
  /// Clears the value of `birthDate`. Subsequent reads from it will return its default value.
  public mutating func clearBirthDate() {_uniqueStorage()._birthDate = nil}

  /// Whether or not this ID has been verified in some way.
  public var verified: Bool {
    get {return _storage._verified}
    set {_uniqueStorage()._verified = newValue}
  }

  /// Globally-provisioned ID for this identification document.
  public var globalID: String {
    get {return _storage._globalID}
    set {_uniqueStorage()._globalID = newValue}
  }

  public var document: OneOf_Document? {
    get {return _storage._document}
    set {_uniqueStorage()._document = newValue}
  }

  /// United States Driver's License.
  public var license: Bloombox_Identity_Ids_USDL {
    get {
      if case .license(let v)? = _storage._document {return v}
      return Bloombox_Identity_Ids_USDL()
    }
    set {_uniqueStorage()._document = .license(newValue)}
  }

  /// National passport.
  public var passport: Bloombox_Identity_Ids_Passport {
    get {
      if case .passport(let v)? = _storage._document {return v}
      return Bloombox_Identity_Ids_Passport()
    }
    set {_uniqueStorage()._document = .passport(newValue)}
  }

  public var unknownFields = SwiftProtobuf.UnknownStorage()

  public enum OneOf_Document: Equatable {
    /// United States Driver's License.
    case license(Bloombox_Identity_Ids_USDL)
    /// National passport.
    case passport(Bloombox_Identity_Ids_Passport)

  #if !swift(>=4.1)
    public static func ==(lhs: Bloombox_Identity_ID.OneOf_Document, rhs: Bloombox_Identity_ID.OneOf_Document) -> Bool {
      switch (lhs, rhs) {
      case (.license(let l), .license(let r)): return l == r
      case (.passport(let l), .passport(let r)): return l == r
      default: return false
      }
    }
  #endif
  }

  public init() {}

  fileprivate var _storage = _StorageClass.defaultInstance
}

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

fileprivate let _protobuf_package = "bloombox.identity"

extension Bloombox_Identity_IDType: SwiftProtobuf._ProtoNameProviding {
  public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
    0: .same(proto: "USDL"),
    1: .same(proto: "PASSPORT"),
  ]
}

extension Bloombox_Identity_IDReference: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
  public static let protoMessageName: String = _protobuf_package + ".IDReference"
  public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
    1: .same(proto: "type"),
    2: .standard(proto: "expire_date"),
    3: .standard(proto: "birth_date"),
    20: .same(proto: "license"),
    21: .same(proto: "passport"),
  ]

  fileprivate class _StorageClass {
    var _type: Bloombox_Identity_IDType = .usdl
    var _expireDate: Opencannabis_Temporal_Date? = nil
    var _birthDate: Opencannabis_Temporal_Date? = nil
    var _document: Bloombox_Identity_IDReference.OneOf_Document?

    static let defaultInstance = _StorageClass()

    private init() {}

    init(copying source: _StorageClass) {
      _type = source._type
      _expireDate = source._expireDate
      _birthDate = source._birthDate
      _document = source._document
    }
  }

  fileprivate mutating func _uniqueStorage() -> _StorageClass {
    if !isKnownUniquelyReferenced(&_storage) {
      _storage = _StorageClass(copying: _storage)
    }
    return _storage
  }

  public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
    _ = _uniqueStorage()
    try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
      while let fieldNumber = try decoder.nextFieldNumber() {
        switch fieldNumber {
        case 1: try decoder.decodeSingularEnumField(value: &_storage._type)
        case 2: try decoder.decodeSingularMessageField(value: &_storage._expireDate)
        case 3: try decoder.decodeSingularMessageField(value: &_storage._birthDate)
        case 20:
          var v: Bloombox_Identity_Ids_USDLReference?
          if let current = _storage._document {
            try decoder.handleConflictingOneOf()
            if case .license(let m) = current {v = m}
          }
          try decoder.decodeSingularMessageField(value: &v)
          if let v = v {_storage._document = .license(v)}
        case 21:
          var v: Bloombox_Identity_Ids_PassportReference?
          if let current = _storage._document {
            try decoder.handleConflictingOneOf()
            if case .passport(let m) = current {v = m}
          }
          try decoder.decodeSingularMessageField(value: &v)
          if let v = v {_storage._document = .passport(v)}
        default: break
        }
      }
    }
  }

  public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
    try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
      if _storage._type != .usdl {
        try visitor.visitSingularEnumField(value: _storage._type, fieldNumber: 1)
      }
      if let v = _storage._expireDate {
        try visitor.visitSingularMessageField(value: v, fieldNumber: 2)
      }
      if let v = _storage._birthDate {
        try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
      }
      switch _storage._document {
      case .license(let v)?:
        try visitor.visitSingularMessageField(value: v, fieldNumber: 20)
      case .passport(let v)?:
        try visitor.visitSingularMessageField(value: v, fieldNumber: 21)
      case nil: break
      }
    }
    try unknownFields.traverse(visitor: &visitor)
  }

  public static func ==(lhs: Bloombox_Identity_IDReference, rhs: Bloombox_Identity_IDReference) -> Bool {
    if lhs._storage !== rhs._storage {
      let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in
        let _storage = _args.0
        let rhs_storage = _args.1
        if _storage._type != rhs_storage._type {return false}
        if _storage._expireDate != rhs_storage._expireDate {return false}
        if _storage._birthDate != rhs_storage._birthDate {return false}
        if _storage._document != rhs_storage._document {return false}
        return true
      }
      if !storagesAreEqual {return false}
    }
    if lhs.unknownFields != rhs.unknownFields {return false}
    return true
  }
}

extension Bloombox_Identity_ID: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
  public static let protoMessageName: String = _protobuf_package + ".ID"
  public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
    1: .same(proto: "type"),
    2: .same(proto: "id"),
    3: .standard(proto: "expire_date"),
    4: .standard(proto: "birth_date"),
    5: .same(proto: "verified"),
    6: .standard(proto: "global_id"),
    20: .same(proto: "license"),
    21: .same(proto: "passport"),
  ]

  fileprivate class _StorageClass {
    var _type: Bloombox_Identity_IDType = .usdl
    var _id: String = String()
    var _expireDate: Opencannabis_Temporal_Date? = nil
    var _birthDate: Opencannabis_Temporal_Date? = nil
    var _verified: Bool = false
    var _globalID: String = String()
    var _document: Bloombox_Identity_ID.OneOf_Document?

    static let defaultInstance = _StorageClass()

    private init() {}

    init(copying source: _StorageClass) {
      _type = source._type
      _id = source._id
      _expireDate = source._expireDate
      _birthDate = source._birthDate
      _verified = source._verified
      _globalID = source._globalID
      _document = source._document
    }
  }

  fileprivate mutating func _uniqueStorage() -> _StorageClass {
    if !isKnownUniquelyReferenced(&_storage) {
      _storage = _StorageClass(copying: _storage)
    }
    return _storage
  }

  public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
    _ = _uniqueStorage()
    try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
      while let fieldNumber = try decoder.nextFieldNumber() {
        switch fieldNumber {
        case 1: try decoder.decodeSingularEnumField(value: &_storage._type)
        case 2: try decoder.decodeSingularStringField(value: &_storage._id)
        case 3: try decoder.decodeSingularMessageField(value: &_storage._expireDate)
        case 4: try decoder.decodeSingularMessageField(value: &_storage._birthDate)
        case 5: try decoder.decodeSingularBoolField(value: &_storage._verified)
        case 6: try decoder.decodeSingularStringField(value: &_storage._globalID)
        case 20:
          var v: Bloombox_Identity_Ids_USDL?
          if let current = _storage._document {
            try decoder.handleConflictingOneOf()
            if case .license(let m) = current {v = m}
          }
          try decoder.decodeSingularMessageField(value: &v)
          if let v = v {_storage._document = .license(v)}
        case 21:
          var v: Bloombox_Identity_Ids_Passport?
          if let current = _storage._document {
            try decoder.handleConflictingOneOf()
            if case .passport(let m) = current {v = m}
          }
          try decoder.decodeSingularMessageField(value: &v)
          if let v = v {_storage._document = .passport(v)}
        default: break
        }
      }
    }
  }

  public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
    try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
      if _storage._type != .usdl {
        try visitor.visitSingularEnumField(value: _storage._type, fieldNumber: 1)
      }
      if !_storage._id.isEmpty {
        try visitor.visitSingularStringField(value: _storage._id, fieldNumber: 2)
      }
      if let v = _storage._expireDate {
        try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
      }
      if let v = _storage._birthDate {
        try visitor.visitSingularMessageField(value: v, fieldNumber: 4)
      }
      if _storage._verified != false {
        try visitor.visitSingularBoolField(value: _storage._verified, fieldNumber: 5)
      }
      if !_storage._globalID.isEmpty {
        try visitor.visitSingularStringField(value: _storage._globalID, fieldNumber: 6)
      }
      switch _storage._document {
      case .license(let v)?:
        try visitor.visitSingularMessageField(value: v, fieldNumber: 20)
      case .passport(let v)?:
        try visitor.visitSingularMessageField(value: v, fieldNumber: 21)
      case nil: break
      }
    }
    try unknownFields.traverse(visitor: &visitor)
  }

  public static func ==(lhs: Bloombox_Identity_ID, rhs: Bloombox_Identity_ID) -> Bool {
    if lhs._storage !== rhs._storage {
      let storagesAreEqual: Bool = withExtendedLifetime((lhs._storage, rhs._storage)) { (_args: (_StorageClass, _StorageClass)) in
        let _storage = _args.0
        let rhs_storage = _args.1
        if _storage._type != rhs_storage._type {return false}
        if _storage._id != rhs_storage._id {return false}
        if _storage._expireDate != rhs_storage._expireDate {return false}
        if _storage._birthDate != rhs_storage._birthDate {return false}
        if _storage._verified != rhs_storage._verified {return false}
        if _storage._globalID != rhs_storage._globalID {return false}
        if _storage._document != rhs_storage._document {return false}
        return true
      }
      if !storagesAreEqual {return false}
    }
    if lhs.unknownFields != rhs.unknownFields {return false}
    return true
  }
}
