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

/// The root node in the resource hierarchy to which a particular entity's
/// (a company, for example) resources belong.
public struct Organization: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. The resource name of the organization. This is the
  /// organization's relative path in the API. Its format is
  /// "organizations/[organization_id]". For example, "organizations/1234".
  public var name: Swift.String = Swift.String()

  /// Output only. A human-readable string that refers to the organization in the
  /// Google Cloud Console. This string is set by the server and cannot be
  /// changed. The string will be set to the primary domain (for example,
  /// "google.com") of the Google Workspace customer that owns the organization.
  public var displayName: Swift.String = Swift.String()

  /// Output only. The organization's current lifecycle state.
  public var state: Organization.State = Organization.State()

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

  /// Output only. Timestamp when the Organization was last modified.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Timestamp when the Organization was requested for deletion.
  public var deleteTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. A checksum computed by the server based on the current value
  /// of the Organization resource. This 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()

  /// The owner of this organization. The owner should be specified on
  /// creation. Once set, it cannot be changed.
  ///
  /// The lifetime of the organization and all of its descendants are bound to
  /// the owner. If the owner is deleted, the organization and all its
  /// descendants will be deleted.
  public var owner: OneOf_Owner? = nil

  /// Initialize a new instance of `Organization`.
  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 = Organization().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 displayName = "displayName"
    case directoryCustomerId = "directoryCustomerId"
    case state = "state"
    case createTime = "createTime"
    case updateTime = "updateTime"
    case deleteTime = "deleteTime"
    case etag = "etag"
  }

  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.state = try container.decode(Organization.State.self, forKey: .state)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
    self.deleteTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .deleteTime)
    self.etag = try container.decode(Swift.String.self, forKey: .etag)

    var owner: OneOf_Owner? = nil
    let ownerCheckAndSet = {
      if owner != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'owner'"))
      }
      owner = $0
    }
    if let directoryCustomerId = try container.decodeIfPresent(
      Swift.String.self, forKey: .directoryCustomerId)
    {
      try ownerCheckAndSet(.directoryCustomerId(directoryCustomerId))
    }
    self.owner = owner
  }

  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.state, forKey: .state)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)
    try container.encode(self.deleteTime, forKey: .deleteTime)
    try container.encode(self.etag, forKey: .etag)

    if let choice = self.owner {
      switch choice {
      case .directoryCustomerId(let value):
        try container.encode(value, forKey: .directoryCustomerId)
      }
    }
  }

  /// Organization lifecycle states.
  public enum State: Codable, Equatable, Sendable {
    /// Unspecified state.  This is only useful for distinguishing unset values.
    case unspecified
    /// The normal and active state.
    case active
    /// The organization has been marked for deletion by the user.
    case deleteRequested
    /// 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 .active: return 1
      case .deleteRequested: 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 "STATE_UNSPECIFIED"
      case .active: return "ACTIVE"
      case .deleteRequested: return "DELETE_REQUESTED"
      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:State/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "STATE_UNSPECIFIED": self = .unspecified
      case "ACTIVE": self = .active
      case "DELETE_REQUESTED": self = .deleteRequested
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:State/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .active
      case 2: self = .deleteRequested
      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 .active: return try container.encode(1)
      case .deleteRequested: return try container.encode(2)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  /// The owner of this organization. The owner should be specified on
  /// creation. Once set, it cannot be changed.
  ///
  /// The lifetime of the organization and all of its descendants are bound to
  /// the owner. If the owner is deleted, the organization and all its
  /// descendants will be deleted.
  public enum OneOf_Owner: Codable, Equatable, Sendable {
    /// Immutable. The G Suite / Workspace customer id used in the Directory API.
    case directoryCustomerId(Swift.String)
  }

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