// Code generated by sidekick. DO NOT EDIT.
//
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#if VertexRagDataService
  import Foundation
  import GoogleCloudWkt

  /// A RagCorpus is a RagFile container and a project can have multiple
  /// RagCorpora.
  public struct RagCorpus: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Output only. The resource name of the RagCorpus.
    public var name: Swift.String = Swift.String()

    /// Required. The display name of the RagCorpus.
    /// The name can be up to 128 characters long and can consist of any UTF-8
    /// characters.
    public var displayName: Swift.String = Swift.String()

    /// Optional. The description of the RagCorpus.
    public var description: Swift.String = Swift.String()

    /// Output only. Timestamp when this RagCorpus was created.
    public var createTime: GoogleCloudWkt.Timestamp? = nil

    /// Output only. Timestamp when this RagCorpus was last updated.
    public var updateTime: GoogleCloudWkt.Timestamp? = nil

    /// Output only. RagCorpus state.
    public var corpusStatus: CorpusStatus? = nil

    /// Optional. Immutable. The CMEK key name used to encrypt at-rest data related
    /// to this Corpus. Only applicable to RagManagedDb option for Vector DB. This
    /// field can only be set at corpus creation time, and cannot be updated or
    /// deleted.
    public var encryptionSpec: EncryptionSpec? = nil

    /// The backend config of the RagCorpus.
    /// It can be data store and/or retrieval engine.
    public var backendConfig: OneOf_BackendConfig? = nil

    /// Initialize a new instance of `RagCorpus`.
    public init() {}

    /// Use `config` to return a new instance of this object, with some fields updated.
    ///
    /// Commonly used to initialize the value, for example:
    ///
    /// ```
    /// let value = RagCorpus().with { $0.vectorDbConfig = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    private enum CodingKeys: Swift.String, CodingKey {
      case vectorDbConfig = "vectorDbConfig"
      case vertexAiSearchConfig = "vertexAiSearchConfig"
      case name = "name"
      case displayName = "displayName"
      case description = "description"
      case createTime = "createTime"
      case updateTime = "updateTime"
      case corpusStatus = "corpusStatus"
      case encryptionSpec = "encryptionSpec"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.name = try container.decode(Swift.String.self, forKey: .name)
      self.displayName = try container.decode(Swift.String.self, forKey: .displayName)
      self.description = try container.decode(Swift.String.self, forKey: .description)
      self.createTime = try container.decodeIfPresent(
        GoogleCloudWkt.Timestamp.self, forKey: .createTime)
      self.updateTime = try container.decodeIfPresent(
        GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
      self.corpusStatus = try container.decodeIfPresent(CorpusStatus.self, forKey: .corpusStatus)
      self.encryptionSpec = try container.decodeIfPresent(
        EncryptionSpec.self, forKey: .encryptionSpec)

      var backendConfig: OneOf_BackendConfig? = nil
      let backendConfigCheckAndSet = {
        if backendConfig != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'backendConfig'"))
        }
        backendConfig = $0
      }
      if let vectorDbConfig = try container.decodeIfPresent(
        RagVectorDbConfig?.self, forKey: .vectorDbConfig)
      {
        try backendConfigCheckAndSet(.vectorDbConfig(vectorDbConfig))
      }
      if let vertexAiSearchConfig = try container.decodeIfPresent(
        VertexAiSearchConfig?.self, forKey: .vertexAiSearchConfig)
      {
        try backendConfigCheckAndSet(.vertexAiSearchConfig(vertexAiSearchConfig))
      }
      self.backendConfig = backendConfig
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      try container.encode(self.name, forKey: .name)
      try container.encode(self.displayName, forKey: .displayName)
      try container.encode(self.description, forKey: .description)
      try container.encode(self.createTime, forKey: .createTime)
      try container.encode(self.updateTime, forKey: .updateTime)
      try container.encode(self.corpusStatus, forKey: .corpusStatus)
      try container.encode(self.encryptionSpec, forKey: .encryptionSpec)

      if let choice = self.backendConfig {
        switch choice {
        case .vectorDbConfig(let value):
          try container.encode(value, forKey: .vectorDbConfig)
        case .vertexAiSearchConfig(let value):
          try container.encode(value, forKey: .vertexAiSearchConfig)
        }
      }
    }

    /// The backend config of the RagCorpus.
    /// It can be data store and/or retrieval engine.
    public enum OneOf_BackendConfig: Codable, Equatable, Sendable {
      /// Optional. Immutable. The config for the Vector DBs.
      indirect case vectorDbConfig(RagVectorDbConfig?)
      /// Optional. Immutable. The config for the Vertex AI Search.
      indirect case vertexAiSearchConfig(VertexAiSearchConfig?)
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.aiplatform.v1.RagCorpus"
    }
    public init(fromAny any: GoogleCloudWkt.`Any`) throws {
      self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
    }
    public func _pack() throws -> GoogleCloudWkt.Struct {
      return try GoogleCloudWkt._slowAnySerialize(message: self)
    }
  }
#endif
