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

// Copyright (c) 2019, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause

import Foundation

// 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: ProtobufAPIVersionCheck {
  struct _2: ProtobufAPIVersion_2 {}
  typealias Version = _2
}

///*
/// A model which wraps another (compiled) model external to this one
struct CoreML_Specification_LinkedModel {
  // 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 linkType: OneOf_LinkType? {
    get {return _storage._linkType}
    set {_uniqueStorage()._linkType = newValue}
  }

  /// A model located via a file system path
  var linkedModelFile: CoreML_Specification_LinkedModelFile {
    get {
      if case .linkedModelFile(let v)? = _storage._linkType {return v}
      return CoreML_Specification_LinkedModelFile()
    }
    set {_uniqueStorage()._linkType = .linkedModelFile(newValue)}
  }

  var unknownFields = UnknownStorage()

  enum OneOf_LinkType: Equatable {
    /// A model located via a file system path
    case linkedModelFile(CoreML_Specification_LinkedModelFile)

  #if !swift(>=4.1)
    static func ==(lhs: CoreML_Specification_LinkedModel.OneOf_LinkType, rhs: CoreML_Specification_LinkedModel.OneOf_LinkType) -> Bool {
      switch (lhs, rhs) {
      case (.linkedModelFile(let l), .linkedModelFile(let r)): return l == r
      }
    }
  #endif
  }

  init() {}

  fileprivate var _storage = _StorageClass.defaultInstance
}

/// Model is referenced by a model file name and search path
struct CoreML_Specification_LinkedModelFile {
  // 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.

  /// Model file name: e.g. "MyFetureExtractor.mlmodelc"
  var linkedModelFileName: CoreML_Specification_StringParameter {
    get {return _storage._linkedModelFileName ?? CoreML_Specification_StringParameter()}
    set {_uniqueStorage()._linkedModelFileName = newValue}
  }
  /// Returns true if `linkedModelFileName` has been explicitly set.
  var hasLinkedModelFileName: Bool {return _storage._linkedModelFileName != nil}
  /// Clears the value of `linkedModelFileName`. Subsequent reads from it will return its default value.
  mutating func clearLinkedModelFileName() {_uniqueStorage()._linkedModelFileName = nil}

  /// Search path to find the linked model file
  /// Multiple paths can be searched using the unix-style path separator ":"
  /// Each path can be relative (to this model) or absolute
  ///
  /// An empty string is the same as teh relative search path "."
  /// which searches in the same location as this model file
  ///
  /// There are some special paths which start with $
  /// - $BUNDLE_MAIN - Indicates to look in the main bundle
  /// - $BUNDLE_IDENTIFIER(identifier) - Looks in Bunde with given identifer
  var linkedModelSearchPath: CoreML_Specification_StringParameter {
    get {return _storage._linkedModelSearchPath ?? CoreML_Specification_StringParameter()}
    set {_uniqueStorage()._linkedModelSearchPath = newValue}
  }
  /// Returns true if `linkedModelSearchPath` has been explicitly set.
  var hasLinkedModelSearchPath: Bool {return _storage._linkedModelSearchPath != nil}
  /// Clears the value of `linkedModelSearchPath`. Subsequent reads from it will return its default value.
  mutating func clearLinkedModelSearchPath() {_uniqueStorage()._linkedModelSearchPath = nil}

  var unknownFields = UnknownStorage()

  init() {}

  fileprivate var _storage = _StorageClass.defaultInstance
}

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

fileprivate let _protobuf_package = "CoreML.Specification"

extension CoreML_Specification_LinkedModel: Message, _MessageImplementationBase, _ProtoNameProviding {
  static let protoMessageName: String = _protobuf_package + ".LinkedModel"
  static let _protobuf_nameMap: _NameMap = [
    1: .same(proto: "linkedModelFile"),
  ]

  fileprivate class _StorageClass {
    var _linkType: CoreML_Specification_LinkedModel.OneOf_LinkType?

    static let defaultInstance = _StorageClass()

    private init() {}

    init(copying source: _StorageClass) {
      _linkType = source._linkType
    }
  }

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

  mutating func decodeMessage<D: Decoder>(decoder: inout D) throws {
    _ = _uniqueStorage()
    try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
      while let fieldNumber = try decoder.nextFieldNumber() {
        switch fieldNumber {
        case 1:
          var v: CoreML_Specification_LinkedModelFile?
          if let current = _storage._linkType {
            try decoder.handleConflictingOneOf()
            if case .linkedModelFile(let m) = current {v = m}
          }
          try decoder.decodeSingularMessageField(value: &v)
          if let v = v {_storage._linkType = .linkedModelFile(v)}
        default: break
        }
      }
    }
  }

  func traverse<V: Visitor>(visitor: inout V) throws {
    try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
      if case .linkedModelFile(let v)? = _storage._linkType {
        try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
      }
    }
    try unknownFields.traverse(visitor: &visitor)
  }

  static func ==(lhs: CoreML_Specification_LinkedModel, rhs: CoreML_Specification_LinkedModel) -> 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._linkType != rhs_storage._linkType {return false}
        return true
      }
      if !storagesAreEqual {return false}
    }
    if lhs.unknownFields != rhs.unknownFields {return false}
    return true
  }
}

extension CoreML_Specification_LinkedModelFile: Message, _MessageImplementationBase, _ProtoNameProviding {
  static let protoMessageName: String = _protobuf_package + ".LinkedModelFile"
  static let _protobuf_nameMap: _NameMap = [
    1: .same(proto: "linkedModelFileName"),
    2: .same(proto: "linkedModelSearchPath"),
  ]

  fileprivate class _StorageClass {
    var _linkedModelFileName: CoreML_Specification_StringParameter? = nil
    var _linkedModelSearchPath: CoreML_Specification_StringParameter? = nil

    static let defaultInstance = _StorageClass()

    private init() {}

    init(copying source: _StorageClass) {
      _linkedModelFileName = source._linkedModelFileName
      _linkedModelSearchPath = source._linkedModelSearchPath
    }
  }

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

  mutating func decodeMessage<D: Decoder>(decoder: inout D) throws {
    _ = _uniqueStorage()
    try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
      while let fieldNumber = try decoder.nextFieldNumber() {
        switch fieldNumber {
        case 1: try decoder.decodeSingularMessageField(value: &_storage._linkedModelFileName)
        case 2: try decoder.decodeSingularMessageField(value: &_storage._linkedModelSearchPath)
        default: break
        }
      }
    }
  }

  func traverse<V: Visitor>(visitor: inout V) throws {
    try withExtendedLifetime(_storage) { (_storage: _StorageClass) in
      if let v = _storage._linkedModelFileName {
        try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
      }
      if let v = _storage._linkedModelSearchPath {
        try visitor.visitSingularMessageField(value: v, fieldNumber: 2)
      }
    }
    try unknownFields.traverse(visitor: &visitor)
  }

  static func ==(lhs: CoreML_Specification_LinkedModelFile, rhs: CoreML_Specification_LinkedModelFile) -> 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._linkedModelFileName != rhs_storage._linkedModelFileName {return false}
        if _storage._linkedModelSearchPath != rhs_storage._linkedModelSearchPath {return false}
        return true
      }
      if !storagesAreEqual {return false}
    }
    if lhs.unknownFields != rhs.unknownFields {return false}
    return true
  }
}
