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

/// Defines a time window during which no backup should
/// happen. All time and date are in UTC.
public struct ExclusionWindow: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. Specifies the start time of the window using time of the day in
  /// UTC.
  public var startTime: GoogleType.TimeOfDay? = nil

  /// Required. Specifies duration of the window.
  /// Duration must be >= 5 minutes and < (target RPO - 20 minutes).
  /// Additional restrictions based on the recurrence type to allow some time for
  /// backup to happen:
  /// - single_occurrence_date:  no restriction, but UI may warn about this when
  /// duration >= target RPO
  /// - daily window: duration < 24 hours
  /// - weekly window:
  ///   - days of week includes all seven days of a week: duration < 24 hours
  ///   - all other weekly window: duration < 168 hours (i.e., 24 * 7 hours)
  public var duration: GoogleCloudWkt.Duration? = nil

  /// Required. Specifies the day(s) on which the exclusion window takes
  /// effect. Exactly one of the fields MUST be specified.
  public var recurrence: OneOf_Recurrence? = nil

  /// Initialize a new instance of `ExclusionWindow`.
  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 = ExclusionWindow().with { $0.startTime = ... }
  /// ```
  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 startTime = "startTime"
    case duration = "duration"
    case singleOccurrenceDate = "singleOccurrenceDate"
    case daily = "daily"
    case daysOfWeek = "daysOfWeek"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.startTime = try container.decodeIfPresent(GoogleType.TimeOfDay.self, forKey: .startTime)
    self.duration = try container.decodeIfPresent(GoogleCloudWkt.Duration.self, forKey: .duration)

    var recurrence: OneOf_Recurrence? = nil
    let recurrenceCheckAndSet = {
      if recurrence != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'recurrence'"))
      }
      recurrence = $0
    }
    if let singleOccurrenceDate = try container.decodeIfPresent(
      GoogleType.Date?.self, forKey: .singleOccurrenceDate)
    {
      try recurrenceCheckAndSet(.singleOccurrenceDate(singleOccurrenceDate))
    }
    if let daily = try container.decodeIfPresent(Swift.Bool.self, forKey: .daily) {
      try recurrenceCheckAndSet(.daily(daily))
    }
    if let daysOfWeek = try container.decodeIfPresent(
      ExclusionWindow.DayOfWeekList?.self, forKey: .daysOfWeek)
    {
      try recurrenceCheckAndSet(.daysOfWeek(daysOfWeek))
    }
    self.recurrence = recurrence
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.startTime, forKey: .startTime)
    try container.encode(self.duration, forKey: .duration)

    if let choice = self.recurrence {
      switch choice {
      case .singleOccurrenceDate(let value):
        try container.encode(value, forKey: .singleOccurrenceDate)
      case .daily(let value):
        try container.encode(value, forKey: .daily)
      case .daysOfWeek(let value):
        try container.encode(value, forKey: .daysOfWeek)
      }
    }
  }

  /// Holds repeated DaysOfWeek values as a container.
  public struct DayOfWeekList: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. A list of days of week.
    public var daysOfWeek: [GoogleType.DayOfWeek] = []

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

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

  /// Required. Specifies the day(s) on which the exclusion window takes
  /// effect. Exactly one of the fields MUST be specified.
  public enum OneOf_Recurrence: Codable, Equatable, Sendable {
    /// No recurrence. The exclusion window occurs only once and on this
    /// date in UTC.
    indirect case singleOccurrenceDate(GoogleType.Date?)
    /// The exclusion window occurs every day if set to "True".
    /// Specifying this field to "False" is an error.
    case daily(Swift.Bool)
    /// The exclusion window occurs on these days of each week in UTC.
    indirect case daysOfWeek(ExclusionWindow.DayOfWeekList?)
  }

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