// 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 SqlUsersService
  import Foundation
  import GoogleCloudWkt

  /// A Cloud SQL user resource.
  public struct User: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// This is always `sql#user`.
    public var kind: Swift.String = Swift.String()

    /// The password for the user.
    public var password: Swift.String = Swift.String()

    /// This field is deprecated and will be removed from a future version of the
    /// API.
    public var etag: Swift.String = Swift.String()

    /// The name of the user in the Cloud SQL instance. Can be omitted for
    /// `update` because it is already specified in the URL.
    public var name: Swift.String = Swift.String()

    /// Optional. The host from which the user can connect. For `insert`
    /// operations, host defaults to an empty string. For `update`
    /// operations, host is specified as part of the request URL. The host name
    /// cannot be updated after insertion.  For a MySQL instance, it's required;
    /// for a PostgreSQL or SQL Server instance, it's optional.
    public var host: Swift.String = Swift.String()

    /// The name of the Cloud SQL instance. This does not include the project ID.
    /// Can be omitted for `update` because it is already specified on the
    /// URL.
    public var instance: Swift.String = Swift.String()

    /// The project ID of the project containing the Cloud SQL database. The Google
    /// apps domain is prefixed if applicable. Can be omitted for `update` because
    /// it is already specified on the URL.
    public var project: Swift.String = Swift.String()

    /// The user type. It determines the method to authenticate the user during
    /// login. The default is the database's built-in user type.
    public var type: User.SqlUserType = User.SqlUserType()

    /// Optional. The full email for an IAM user. For normal database users, this
    /// will not be filled. Only applicable to MySQL database users.
    public var iamEmail: Swift.String = Swift.String()

    /// User level password validation policy.
    public var passwordPolicy: UserPasswordValidationPolicy? = nil

    /// Dual password status for the user.
    public var dualPasswordType: User.DualPasswordType? = nil

    /// Indicates if a group is active or inactive for IAM database authentication.
    public var iamStatus: User.IamStatus? = nil

    /// Optional. Role memberships of the user
    public var databaseRoles: [Swift.String] = []

    /// Optional. The server roles for the SQL Server login.
    public var serverRoles: [Swift.String] = []

    /// User details for specific database type
    public var userDetails: OneOf_UserDetails? = nil

    /// Initialize a new instance of `User`.
    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 = User().with { $0.kind = ... }
    /// ```
    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 kind = "kind"
      case password = "password"
      case etag = "etag"
      case name = "name"
      case host = "host"
      case instance = "instance"
      case project = "project"
      case type = "type"
      case sqlserverUserDetails = "sqlserverUserDetails"
      case iamEmail = "iamEmail"
      case passwordPolicy = "passwordPolicy"
      case dualPasswordType = "dualPasswordType"
      case iamStatus = "iamStatus"
      case databaseRoles = "databaseRoles"
      case serverRoles = "serverRoles"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.kind = try container.decode(Swift.String.self, forKey: .kind)
      self.password = try container.decode(Swift.String.self, forKey: .password)
      self.etag = try container.decode(Swift.String.self, forKey: .etag)
      self.name = try container.decode(Swift.String.self, forKey: .name)
      self.host = try container.decode(Swift.String.self, forKey: .host)
      self.instance = try container.decode(Swift.String.self, forKey: .instance)
      self.project = try container.decode(Swift.String.self, forKey: .project)
      self.type = try container.decode(User.SqlUserType.self, forKey: .type)
      self.iamEmail = try container.decode(Swift.String.self, forKey: .iamEmail)
      self.passwordPolicy = try container.decodeIfPresent(
        UserPasswordValidationPolicy.self, forKey: .passwordPolicy)
      self.dualPasswordType = try container.decodeIfPresent(
        User.DualPasswordType.self, forKey: .dualPasswordType)
      self.iamStatus = try container.decodeIfPresent(User.IamStatus.self, forKey: .iamStatus)
      self.databaseRoles = try container.decode([Swift.String].self, forKey: .databaseRoles)
      self.serverRoles = try container.decode([Swift.String].self, forKey: .serverRoles)

      var userDetails: OneOf_UserDetails? = nil
      let userDetailsCheckAndSet = {
        if userDetails != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'userDetails'"))
        }
        userDetails = $0
      }
      if let sqlserverUserDetails = try container.decodeIfPresent(
        SqlServerUserDetails?.self, forKey: .sqlserverUserDetails)
      {
        try userDetailsCheckAndSet(.sqlserverUserDetails(sqlserverUserDetails))
      }
      self.userDetails = userDetails
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      try container.encode(self.kind, forKey: .kind)
      try container.encode(self.password, forKey: .password)
      try container.encode(self.etag, forKey: .etag)
      try container.encode(self.name, forKey: .name)
      try container.encode(self.host, forKey: .host)
      try container.encode(self.instance, forKey: .instance)
      try container.encode(self.project, forKey: .project)
      try container.encode(self.type, forKey: .type)
      try container.encode(self.iamEmail, forKey: .iamEmail)
      try container.encode(self.passwordPolicy, forKey: .passwordPolicy)
      try container.encode(self.dualPasswordType, forKey: .dualPasswordType)
      try container.encode(self.iamStatus, forKey: .iamStatus)
      try container.encode(self.databaseRoles, forKey: .databaseRoles)
      try container.encode(self.serverRoles, forKey: .serverRoles)

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

    /// The user type.
    public enum SqlUserType: Codable, Equatable, Sendable {
      /// The database's built-in user type.
      case builtIn
      /// Cloud IAM user.
      case cloudIamUser
      /// Cloud IAM service account.
      case cloudIamServiceAccount
      /// Cloud IAM group. Not used for login.
      case cloudIamGroup
      /// Read-only. Login for a user that belongs to the Cloud IAM group.
      case cloudIamGroupUser
      /// Read-only. Login for a service account that belongs to the
      /// Cloud IAM group.
      case cloudIamGroupServiceAccount
      /// Cloud IAM workforce identity user managed via workforce identity
      /// federation.
      case cloudIamWorkforceIdentity
      /// Microsoft Entra ID user.
      case entraidUser
      /// 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 = .builtIn
      }

      /// 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 .builtIn: return 0
        case .cloudIamUser: return 1
        case .cloudIamServiceAccount: return 2
        case .cloudIamGroup: return 3
        case .cloudIamGroupUser: return 4
        case .cloudIamGroupServiceAccount: return 5
        case .cloudIamWorkforceIdentity: return 6
        case .entraidUser: return 7
        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 .builtIn: return "BUILT_IN"
        case .cloudIamUser: return "CLOUD_IAM_USER"
        case .cloudIamServiceAccount: return "CLOUD_IAM_SERVICE_ACCOUNT"
        case .cloudIamGroup: return "CLOUD_IAM_GROUP"
        case .cloudIamGroupUser: return "CLOUD_IAM_GROUP_USER"
        case .cloudIamGroupServiceAccount: return "CLOUD_IAM_GROUP_SERVICE_ACCOUNT"
        case .cloudIamWorkforceIdentity: return "CLOUD_IAM_WORKFORCE_IDENTITY"
        case .entraidUser: return "ENTRAID_USER"
        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:SqlUserType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "BUILT_IN": self = .builtIn
        case "CLOUD_IAM_USER": self = .cloudIamUser
        case "CLOUD_IAM_SERVICE_ACCOUNT": self = .cloudIamServiceAccount
        case "CLOUD_IAM_GROUP": self = .cloudIamGroup
        case "CLOUD_IAM_GROUP_USER": self = .cloudIamGroupUser
        case "CLOUD_IAM_GROUP_SERVICE_ACCOUNT": self = .cloudIamGroupServiceAccount
        case "CLOUD_IAM_WORKFORCE_IDENTITY": self = .cloudIamWorkforceIdentity
        case "ENTRAID_USER": self = .entraidUser
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:SqlUserType/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .builtIn
        case 1: self = .cloudIamUser
        case 2: self = .cloudIamServiceAccount
        case 3: self = .cloudIamGroup
        case 4: self = .cloudIamGroupUser
        case 5: self = .cloudIamGroupServiceAccount
        case 6: self = .cloudIamWorkforceIdentity
        case 7: self = .entraidUser
        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 .builtIn: return try container.encode(0)
        case .cloudIamUser: return try container.encode(1)
        case .cloudIamServiceAccount: return try container.encode(2)
        case .cloudIamGroup: return try container.encode(3)
        case .cloudIamGroupUser: return try container.encode(4)
        case .cloudIamGroupServiceAccount: return try container.encode(5)
        case .cloudIamWorkforceIdentity: return try container.encode(6)
        case .entraidUser: return try container.encode(7)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    /// The type of retained password.
    public enum DualPasswordType: Codable, Equatable, Sendable {
      /// The default value.
      case unspecified
      /// Do not update the user's dual password status.
      case noModifyDualPassword
      /// No dual password usable for connecting using this user.
      case noDualPassword
      /// Dual password usable for connecting using this user.
      case dualPassword
      /// 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 .noModifyDualPassword: return 1
        case .noDualPassword: return 2
        case .dualPassword: return 3
        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 "DUAL_PASSWORD_TYPE_UNSPECIFIED"
        case .noModifyDualPassword: return "NO_MODIFY_DUAL_PASSWORD"
        case .noDualPassword: return "NO_DUAL_PASSWORD"
        case .dualPassword: return "DUAL_PASSWORD"
        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:DualPasswordType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "DUAL_PASSWORD_TYPE_UNSPECIFIED": self = .unspecified
        case "NO_MODIFY_DUAL_PASSWORD": self = .noModifyDualPassword
        case "NO_DUAL_PASSWORD": self = .noDualPassword
        case "DUAL_PASSWORD": self = .dualPassword
        default: self = .unknownStringValue(stringValue)
        }
      }

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

    /// Indicates if a group is available for IAM database authentication.
    public enum IamStatus: Codable, Equatable, Sendable {
      /// The default value for users that are not of type CLOUD_IAM_GROUP.
      /// Only CLOUD_IAM_GROUP users will be inactive or active.
      /// Users with an IamStatus of IAM_STATUS_UNSPECIFIED will not
      /// display whether they are active or inactive as that is not applicable to
      /// them.
      case unspecified
      /// INACTIVE indicates a group is not available for IAM database
      /// authentication.
      case inactive
      /// ACTIVE indicates a group is available for IAM database authentication.
      case active
      /// 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 .inactive: return 1
        case .active: 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 "IAM_STATUS_UNSPECIFIED"
        case .inactive: return "INACTIVE"
        case .active: return "ACTIVE"
        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:IamStatus/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "IAM_STATUS_UNSPECIFIED": self = .unspecified
        case "INACTIVE": self = .inactive
        case "ACTIVE": self = .active
        default: self = .unknownStringValue(stringValue)
        }
      }

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

    /// User details for specific database type
    public enum OneOf_UserDetails: Codable, Equatable, Sendable {
      indirect case sqlserverUserDetails(SqlServerUserDetails?)
    }

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