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

/// A `Target` resource in the Cloud Deploy API.
///
/// A `Target` defines a location to which a Skaffold configuration
/// can be deployed.
public struct Target: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Identifier. Name of the `Target`. Format is
  /// `projects/{project}/locations/{location}/targets/{target}`.
  /// The `target` component must match `[a-z]([a-z0-9-]{0,61}[a-z0-9])?`
  public var name: Swift.String = Swift.String()

  /// Output only. Resource id of the `Target`.
  public var targetId: Swift.String = Swift.String()

  /// Output only. Unique identifier of the `Target`.
  public var uid: Swift.String = Swift.String()

  /// Optional. Description of the `Target`. Max length is 255 characters.
  public var description: Swift.String = Swift.String()

  /// Optional. User annotations. These attributes can only be set and used by
  /// the user, and not by Cloud Deploy. See
  /// https://google.aip.dev/128#annotations for more details such as format and
  /// size limitations.
  public var annotations: [Swift.String: Swift.String] = [:]

  /// Optional. Labels are attributes that can be set and used by both the
  /// user and by Cloud Deploy. Labels must meet the following constraints:
  ///
  /// * Keys and values can contain only lowercase letters, numeric characters,
  /// underscores, and dashes.
  /// * All characters must use UTF-8 encoding, and international characters are
  /// allowed.
  /// * Keys must start with a lowercase letter or international character.
  /// * Each resource is limited to a maximum of 64 labels.
  ///
  /// Both keys and values are additionally constrained to be <= 128 bytes.
  public var labels: [Swift.String: Swift.String] = [:]

  /// Optional. Whether or not the `Target` requires approval.
  public var requireApproval: Swift.Bool = Swift.Bool()

  /// Output only. Time at which the `Target` was created.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Most recent time at which the `Target` was updated.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// Optional. Map of entity IDs to their associated entities. Associated
  /// entities allows specifying places other than the deployment target for
  /// specific features. For example, the Gateway API canary can be configured to
  /// deploy the HTTPRoute to a different cluster(s) than the deployment cluster
  /// using associated entities. An entity ID must consist of lower-case letters,
  /// numbers, and hyphens, start with a letter and end with a letter or a
  /// number, and have a max length of 63 characters. In other words, it must
  /// match the following regex: `^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$`.
  public var associatedEntities: [Swift.String: AssociatedEntities] = [:]

  /// Optional. This checksum is computed by the server based on the value of
  /// other fields, and may be sent on update and delete requests to ensure the
  /// client has an up-to-date value before proceeding.
  public var etag: Swift.String = Swift.String()

  /// Optional. Configurations for all execution that relates to this `Target`.
  /// Each `ExecutionEnvironmentUsage` value may only be used in a single
  /// configuration; using the same value multiple times is an error.
  /// When one or more configurations are specified, they must include the
  /// `RENDER` and `DEPLOY` `ExecutionEnvironmentUsage` values.
  /// When no configurations are specified, execution will use the default
  /// specified in `DefaultPool`.
  public var executionConfigs: [ExecutionConfig] = []

  /// Optional. The deploy parameters to use for this target.
  public var deployParameters: [Swift.String: Swift.String] = [:]

  /// Destination to which the Skaffold configuration is applied during a
  /// rollout.
  public var deploymentTarget: OneOf_DeploymentTarget? = nil

  /// Initialize a new instance of `Target`.
  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 = Target().with { $0.name = ... }
  /// ```
  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 name = "name"
    case targetId = "targetId"
    case uid = "uid"
    case description = "description"
    case annotations = "annotations"
    case labels = "labels"
    case requireApproval = "requireApproval"
    case createTime = "createTime"
    case updateTime = "updateTime"
    case gke = "gke"
    case anthosCluster = "anthosCluster"
    case run = "run"
    case multiTarget = "multiTarget"
    case customTarget = "customTarget"
    case associatedEntities = "associatedEntities"
    case etag = "etag"
    case executionConfigs = "executionConfigs"
    case deployParameters = "deployParameters"
  }

  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.targetId = try container.decode(Swift.String.self, forKey: .targetId)
    self.uid = try container.decode(Swift.String.self, forKey: .uid)
    self.description = try container.decode(Swift.String.self, forKey: .description)
    self.annotations = try container.decode([Swift.String: Swift.String].self, forKey: .annotations)
    self.labels = try container.decode([Swift.String: Swift.String].self, forKey: .labels)
    self.requireApproval = try container.decode(Swift.Bool.self, forKey: .requireApproval)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
    self.associatedEntities = try container.decode(
      [Swift.String: AssociatedEntities].self, forKey: .associatedEntities)
    self.etag = try container.decode(Swift.String.self, forKey: .etag)
    self.executionConfigs = try container.decode([ExecutionConfig].self, forKey: .executionConfigs)
    self.deployParameters = try container.decode(
      [Swift.String: Swift.String].self, forKey: .deployParameters)

    var deploymentTarget: OneOf_DeploymentTarget? = nil
    let deploymentTargetCheckAndSet = {
      if deploymentTarget != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'deploymentTarget'"))
      }
      deploymentTarget = $0
    }
    if let gke = try container.decodeIfPresent(GkeCluster?.self, forKey: .gke) {
      try deploymentTargetCheckAndSet(.gke(gke))
    }
    if let anthosCluster = try container.decodeIfPresent(
      AnthosCluster?.self, forKey: .anthosCluster)
    {
      try deploymentTargetCheckAndSet(.anthosCluster(anthosCluster))
    }
    if let run = try container.decodeIfPresent(CloudRunLocation?.self, forKey: .run) {
      try deploymentTargetCheckAndSet(.run(run))
    }
    if let multiTarget = try container.decodeIfPresent(MultiTarget?.self, forKey: .multiTarget) {
      try deploymentTargetCheckAndSet(.multiTarget(multiTarget))
    }
    if let customTarget = try container.decodeIfPresent(CustomTarget?.self, forKey: .customTarget) {
      try deploymentTargetCheckAndSet(.customTarget(customTarget))
    }
    self.deploymentTarget = deploymentTarget
  }

  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.targetId, forKey: .targetId)
    try container.encode(self.uid, forKey: .uid)
    try container.encode(self.description, forKey: .description)
    try container.encode(self.annotations, forKey: .annotations)
    try container.encode(self.labels, forKey: .labels)
    try container.encode(self.requireApproval, forKey: .requireApproval)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)
    try container.encode(self.associatedEntities, forKey: .associatedEntities)
    try container.encode(self.etag, forKey: .etag)
    try container.encode(self.executionConfigs, forKey: .executionConfigs)
    try container.encode(self.deployParameters, forKey: .deployParameters)

    if let choice = self.deploymentTarget {
      switch choice {
      case .gke(let value):
        try container.encode(value, forKey: .gke)
      case .anthosCluster(let value):
        try container.encode(value, forKey: .anthosCluster)
      case .run(let value):
        try container.encode(value, forKey: .run)
      case .multiTarget(let value):
        try container.encode(value, forKey: .multiTarget)
      case .customTarget(let value):
        try container.encode(value, forKey: .customTarget)
      }
    }
  }

  /// Destination to which the Skaffold configuration is applied during a
  /// rollout.
  public enum OneOf_DeploymentTarget: Codable, Equatable, Sendable {
    /// Optional. Information specifying a GKE Cluster.
    indirect case gke(GkeCluster?)
    /// Optional. Information specifying an Anthos Cluster.
    indirect case anthosCluster(AnthosCluster?)
    /// Optional. Information specifying a Cloud Run deployment target.
    indirect case run(CloudRunLocation?)
    /// Optional. Information specifying a multiTarget.
    indirect case multiTarget(MultiTarget?)
    /// Optional. Information specifying a Custom Target.
    indirect case customTarget(CustomTarget?)
  }

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