// 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 Google Stackdriver dashboard. Dashboards define the content and layout
/// of pages in the Stackdriver web application.
public struct Dashboard: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Identifier. The resource name of the dashboard.
  public var name: Swift.String = Swift.String()

  /// Required. The mutable, human-readable name.
  public var displayName: Swift.String = Swift.String()

  /// `etag` is used for optimistic concurrency control as a way to help
  /// prevent simultaneous updates of a policy from overwriting each other.
  /// An `etag` is returned in the response to `GetDashboard`, and
  /// users are expected to put that etag in the request to `UpdateDashboard` to
  /// ensure that their change will be applied to the same version of the
  /// Dashboard configuration. The field should not be passed during
  /// dashboard creation.
  public var etag: Swift.String = Swift.String()

  /// Filters to reduce the amount of data charted based on the filter criteria.
  public var dashboardFilters: [DashboardFilter] = []

  /// Labels applied to the dashboard
  public var labels: [Swift.String: Swift.String] = [:]

  /// A dashboard's root container element that defines the layout style.
  public var layout: OneOf_Layout? = nil

  /// Initialize a new instance of `Dashboard`.
  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 = Dashboard().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 etag = "etag"
    case gridLayout = "gridLayout"
    case mosaicLayout = "mosaicLayout"
    case rowLayout = "rowLayout"
    case columnLayout = "columnLayout"
    case dashboardFilters = "dashboardFilters"
    case labels = "labels"
  }

  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.etag = try container.decode(Swift.String.self, forKey: .etag)
    self.dashboardFilters = try container.decode([DashboardFilter].self, forKey: .dashboardFilters)
    self.labels = try container.decode([Swift.String: Swift.String].self, forKey: .labels)

    var layout: OneOf_Layout? = nil
    let layoutCheckAndSet = {
      if layout != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'layout'"))
      }
      layout = $0
    }
    if let gridLayout = try container.decodeIfPresent(GridLayout?.self, forKey: .gridLayout) {
      try layoutCheckAndSet(.gridLayout(gridLayout))
    }
    if let mosaicLayout = try container.decodeIfPresent(MosaicLayout?.self, forKey: .mosaicLayout) {
      try layoutCheckAndSet(.mosaicLayout(mosaicLayout))
    }
    if let rowLayout = try container.decodeIfPresent(RowLayout?.self, forKey: .rowLayout) {
      try layoutCheckAndSet(.rowLayout(rowLayout))
    }
    if let columnLayout = try container.decodeIfPresent(ColumnLayout?.self, forKey: .columnLayout) {
      try layoutCheckAndSet(.columnLayout(columnLayout))
    }
    self.layout = layout
  }

  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.etag, forKey: .etag)
    try container.encode(self.dashboardFilters, forKey: .dashboardFilters)
    try container.encode(self.labels, forKey: .labels)

    if let choice = self.layout {
      switch choice {
      case .gridLayout(let value):
        try container.encode(value, forKey: .gridLayout)
      case .mosaicLayout(let value):
        try container.encode(value, forKey: .mosaicLayout)
      case .rowLayout(let value):
        try container.encode(value, forKey: .rowLayout)
      case .columnLayout(let value):
        try container.encode(value, forKey: .columnLayout)
      }
    }
  }

  /// A dashboard's root container element that defines the layout style.
  public enum OneOf_Layout: Codable, Equatable, Sendable {
    /// Content is arranged with a basic layout that re-flows a simple list of
    /// informational elements like widgets or tiles.
    indirect case gridLayout(GridLayout?)
    /// The content is arranged as a grid of tiles, with each content widget
    /// occupying one or more grid blocks.
    indirect case mosaicLayout(MosaicLayout?)
    /// The content is divided into equally spaced rows and the widgets are
    /// arranged horizontally.
    indirect case rowLayout(RowLayout?)
    /// The content is divided into equally spaced columns and the widgets are
    /// arranged vertically.
    indirect case columnLayout(ColumnLayout?)
  }

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