// 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.

import Foundation
import GoogleCloudWkt

/// Request message for
/// [AgentService.ImportApp][google.cloud.ces.v1.AgentService.ImportApp].
///
/// [google.cloud.ces.v1.AgentService.ImportApp]: <doc:AgentService/importApp(request:)>
public struct ImportAppRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. The parent resource name with the location of the app to import.
  public var parent: Swift.String = Swift.String()

  /// Optional. The display name of the app to import.
  /// * If the app is created on import, and the display name is specified,
  /// the imported app will use this display name. If a conflict is detected
  /// with an existing app, a timestamp will be appended to the display name
  /// to make it unique.
  /// * If the app is a reimport, this field should not be set. Providing a
  /// display name during reimport will result in an INVALID_ARGUMENT error.
  public var displayName: Swift.String = Swift.String()

  /// Optional. The ID to use for the imported app.
  /// *  If not specified, a unique ID will be automatically assigned for
  /// the app.
  /// *  Otherwise, the imported app will use this ID as the final component of
  /// its resource name. If an app with the same ID already exists at the
  /// specified location in the project, the content of the existing app will be
  /// replaced.
  public var appId: Swift.String = Swift.String()

  /// Optional. Options governing the import process for the app.
  public var importOptions: ImportAppRequest.ImportOptions? = nil

  /// Optional. Flag for overriding the app lock during import.
  /// If set to true, the import process will ignore the app lock.
  public var ignoreAppLock: Swift.Bool = Swift.Bool()

  /// The app to import.
  public var app: OneOf_App? = nil

  /// Initialize a new instance of `ImportAppRequest`.
  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 = ImportAppRequest().with { $0.gcsUri = ... }
  /// ```
  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 gcsUri = "gcsUri"
    case appContent = "appContent"
    case parent = "parent"
    case displayName = "displayName"
    case appId = "appId"
    case importOptions = "importOptions"
    case ignoreAppLock = "ignoreAppLock"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.parent = try container.decode(Swift.String.self, forKey: .parent)
    self.displayName = try container.decode(Swift.String.self, forKey: .displayName)
    self.appId = try container.decode(Swift.String.self, forKey: .appId)
    self.importOptions = try container.decodeIfPresent(
      ImportAppRequest.ImportOptions.self, forKey: .importOptions)
    self.ignoreAppLock = try container.decode(Swift.Bool.self, forKey: .ignoreAppLock)

    var app: OneOf_App? = nil
    let appCheckAndSet = {
      if app != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath, debugDescription: "Multiple values set for oneof 'app'")
        )
      }
      app = $0
    }
    if let gcsUri = try container.decodeIfPresent(Swift.String.self, forKey: .gcsUri) {
      try appCheckAndSet(.gcsUri(gcsUri))
    }
    if let appContent = try container.decodeIfPresent(Foundation.Data.self, forKey: .appContent) {
      try appCheckAndSet(.appContent(appContent))
    }
    self.app = app
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.parent, forKey: .parent)
    try container.encode(self.displayName, forKey: .displayName)
    try container.encode(self.appId, forKey: .appId)
    try container.encode(self.importOptions, forKey: .importOptions)
    try container.encode(self.ignoreAppLock, forKey: .ignoreAppLock)

    if let choice = self.app {
      switch choice {
      case .gcsUri(let value):
        try container.encode(value, forKey: .gcsUri)
      case .appContent(let value):
        try container.encode(value, forKey: .appContent)
      }
    }
  }

  /// Configuration options for the app import process.
  /// These options control how the import behaves, particularly when
  /// conflicts arise with existing app data.
  public struct ImportOptions: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The strategy to use when resolving conflicts during import.
    public var conflictResolutionStrategy:
      ImportAppRequest.ImportOptions.ConflictResolutionStrategy = ImportAppRequest.ImportOptions
        .ConflictResolutionStrategy()

    /// Initialize a new instance of `ImportOptions`.
    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 = ImportOptions().with { $0.conflictResolutionStrategy = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    /// Defines the strategy for handling conflicts when an app with the same ID
    /// already exists, or when imported resources (like Agents, Tools, etc.)
    /// have the same display names as existing resources within that app.
    public enum ConflictResolutionStrategy: Codable, Equatable, Sendable {
      /// The conflict resolution strategy is unspecified.
      case unspecified
      /// Replace existing data with imported data.
      /// If an app with the same `app_id` already exists, its content will be
      /// updated based on the imported app.
      /// - Resources (App, Agents, Tools, Examples, Guardrails, Toolsets) in the
      ///   imported app that have the same display name as existing resources
      ///   will overwrite the existing ones.
      /// - Imported resources with new display names will be created.
      /// - Existing resources that do not have a matching display name in the
      ///   imported app will remain untouched.
      case replace
      /// Overwrite existing data with imported data.
      /// If an app with the same `app_id` already exists, its content will be
      /// overwritten with the imported app.
      /// - Existing resources (Agents, Tools, Examples, Guardrails, Toolsets) in
      ///   the app will be deleted.
      /// - Imported resources will be created as new resources.
      case overwrite
      /// Encodes an unknown integer value.
      ///
      /// The most common cause for an unknown values is for the service to send
      /// a value unknown to the library. We recommend you update your library to
      /// the latest version.
      case unknownIntValue(Int)
      /// Encodes an unknown string value.
      ///
      /// The most common cause for an unknown values is for the service to send
      /// a value unknown to the library. We recommend you update your library to
      /// the latest version.
      case unknownStringValue(String)

      public init() {
        self = .unspecified
      }

      /// Returns the integer value associated with the enumeration.
      ///
      /// If the enumeration was initialized with an unknown string value, this returns `nil`.
      public var intValue: Int? {
        switch self {
        case .unspecified: return 0
        case .replace: return 1
        case .overwrite: return 2
        case .unknownIntValue(let v): return v
        case .unknownStringValue: return nil
        }
      }

      /// Returns the string value (or name) associated with the enumeration.
      ///
      /// If the enumeration was initialized with an unknown integer value, this returns `nil`.
      public var stringValue: Swift.String? {
        switch self {
        case .unspecified: return "CONFLICT_RESOLUTION_STRATEGY_UNSPECIFIED"
        case .replace: return "REPLACE"
        case .overwrite: return "OVERWRITE"
        case .unknownIntValue: return nil
        case .unknownStringValue(let v): return v
        }
      }

      /// Initialize from a string value.
      ///
      /// If the value is unknown, this initializes to [`unknownStringValue`](doc:ConflictResolutionStrategy/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "CONFLICT_RESOLUTION_STRATEGY_UNSPECIFIED": self = .unspecified
        case "REPLACE": self = .replace
        case "OVERWRITE": self = .overwrite
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:ConflictResolutionStrategy/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .replace
        case 2: self = .overwrite
        default: self = .unknownIntValue(intValue)
        }
      }

      public init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        if let v = try? container.decode(Int.self) {
          self.init(intValue: v)
          return
        }
        if let s = try? container.decode(String.self) {
          if let v = Int(s) {
            self.init(intValue: v)
          } else {
            self.init(stringValue: s)
          }
          return
        }
        throw DecodingError.dataCorruptedError(
          in: container, debugDescription: "Expected enum value, must be integer or string.")
      }

      public func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        switch self {
        case .unspecified: return try container.encode(0)
        case .replace: return try container.encode(1)
        case .overwrite: return try container.encode(2)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.ces.v1.ImportAppRequest.ImportOptions"
    }
    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)
    }
  }

  /// The app to import.
  public enum OneOf_App: Codable, Equatable, Sendable {
    /// The [Google Cloud Storage](https://cloud.google.com/storage/docs/) URI
    /// from which to import app. The format of this URI must be
    /// `gs://<bucket-name>/<object-name>`.
    case gcsUri(Swift.String)
    /// Raw bytes representing the compressed zip file with the app folder
    /// structure.
    case appContent(Foundation.Data)
  }

  public static var _anyTypeUrl: Swift.String {
    return "type.googleapis.com/google.cloud.ces.v1.ImportAppRequest"
  }
  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)
  }
}
