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

/// Widget contains a single dashboard component and configuration of how to
/// present the component in the dashboard.
public struct Widget: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. The title of the widget.
  public var title: Swift.String = Swift.String()

  /// Optional. The widget id. Ids may be made up of alphanumerics, dashes and
  /// underscores. Widget ids are optional.
  public var id: Swift.String = Swift.String()

  /// Content defines the component used to populate the widget.
  public var content: OneOf_Content? = nil

  /// Initialize a new instance of `Widget`.
  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 = Widget().with { $0.title = ... }
  /// ```
  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 title = "title"
    case xyChart = "xyChart"
    case scorecard = "scorecard"
    case text = "text"
    case blank = "blank"
    case alertChart = "alertChart"
    case timeSeriesTable = "timeSeriesTable"
    case collapsibleGroup = "collapsibleGroup"
    case logsPanel = "logsPanel"
    case incidentList = "incidentList"
    case pieChart = "pieChart"
    case errorReportingPanel = "errorReportingPanel"
    case sectionHeader = "sectionHeader"
    case singleViewGroup = "singleViewGroup"
    case id = "id"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.title = try container.decode(Swift.String.self, forKey: .title)
    self.id = try container.decode(Swift.String.self, forKey: .id)

    var content: OneOf_Content? = nil
    let contentCheckAndSet = {
      if content != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'content'"))
      }
      content = $0
    }
    if let xyChart = try container.decodeIfPresent(XyChart?.self, forKey: .xyChart) {
      try contentCheckAndSet(.xyChart(xyChart))
    }
    if let scorecard = try container.decodeIfPresent(Scorecard?.self, forKey: .scorecard) {
      try contentCheckAndSet(.scorecard(scorecard))
    }
    if let text = try container.decodeIfPresent(Text?.self, forKey: .text) {
      try contentCheckAndSet(.text(text))
    }
    if let blank = try container.decodeIfPresent(GoogleCloudWkt.Empty?.self, forKey: .blank) {
      try contentCheckAndSet(.blank(blank))
    }
    if let alertChart = try container.decodeIfPresent(AlertChart?.self, forKey: .alertChart) {
      try contentCheckAndSet(.alertChart(alertChart))
    }
    if let timeSeriesTable = try container.decodeIfPresent(
      TimeSeriesTable?.self, forKey: .timeSeriesTable)
    {
      try contentCheckAndSet(.timeSeriesTable(timeSeriesTable))
    }
    if let collapsibleGroup = try container.decodeIfPresent(
      CollapsibleGroup?.self, forKey: .collapsibleGroup)
    {
      try contentCheckAndSet(.collapsibleGroup(collapsibleGroup))
    }
    if let logsPanel = try container.decodeIfPresent(LogsPanel?.self, forKey: .logsPanel) {
      try contentCheckAndSet(.logsPanel(logsPanel))
    }
    if let incidentList = try container.decodeIfPresent(IncidentList?.self, forKey: .incidentList) {
      try contentCheckAndSet(.incidentList(incidentList))
    }
    if let pieChart = try container.decodeIfPresent(PieChart?.self, forKey: .pieChart) {
      try contentCheckAndSet(.pieChart(pieChart))
    }
    if let errorReportingPanel = try container.decodeIfPresent(
      ErrorReportingPanel?.self, forKey: .errorReportingPanel)
    {
      try contentCheckAndSet(.errorReportingPanel(errorReportingPanel))
    }
    if let sectionHeader = try container.decodeIfPresent(
      SectionHeader?.self, forKey: .sectionHeader)
    {
      try contentCheckAndSet(.sectionHeader(sectionHeader))
    }
    if let singleViewGroup = try container.decodeIfPresent(
      SingleViewGroup?.self, forKey: .singleViewGroup)
    {
      try contentCheckAndSet(.singleViewGroup(singleViewGroup))
    }
    self.content = content
  }

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

    if let choice = self.content {
      switch choice {
      case .xyChart(let value):
        try container.encode(value, forKey: .xyChart)
      case .scorecard(let value):
        try container.encode(value, forKey: .scorecard)
      case .text(let value):
        try container.encode(value, forKey: .text)
      case .blank(let value):
        try container.encode(value, forKey: .blank)
      case .alertChart(let value):
        try container.encode(value, forKey: .alertChart)
      case .timeSeriesTable(let value):
        try container.encode(value, forKey: .timeSeriesTable)
      case .collapsibleGroup(let value):
        try container.encode(value, forKey: .collapsibleGroup)
      case .logsPanel(let value):
        try container.encode(value, forKey: .logsPanel)
      case .incidentList(let value):
        try container.encode(value, forKey: .incidentList)
      case .pieChart(let value):
        try container.encode(value, forKey: .pieChart)
      case .errorReportingPanel(let value):
        try container.encode(value, forKey: .errorReportingPanel)
      case .sectionHeader(let value):
        try container.encode(value, forKey: .sectionHeader)
      case .singleViewGroup(let value):
        try container.encode(value, forKey: .singleViewGroup)
      }
    }
  }

  /// Content defines the component used to populate the widget.
  public enum OneOf_Content: Codable, Equatable, Sendable {
    /// A chart of time series data.
    indirect case xyChart(XyChart?)
    /// A scorecard summarizing time series data.
    indirect case scorecard(Scorecard?)
    /// A raw string or markdown displaying textual content.
    indirect case text(Text?)
    /// A blank space.
    indirect case blank(GoogleCloudWkt.Empty?)
    /// A chart of alert policy data.
    indirect case alertChart(AlertChart?)
    /// A widget that displays time series data in a tabular format.
    indirect case timeSeriesTable(TimeSeriesTable?)
    /// A widget that groups the other widgets. All widgets that are within
    /// the area spanned by the grouping widget are considered member widgets.
    indirect case collapsibleGroup(CollapsibleGroup?)
    /// A widget that shows a stream of logs.
    indirect case logsPanel(LogsPanel?)
    /// A widget that shows list of incidents.
    indirect case incidentList(IncidentList?)
    /// A widget that displays timeseries data as a pie chart.
    indirect case pieChart(PieChart?)
    /// A widget that displays a list of error groups.
    indirect case errorReportingPanel(ErrorReportingPanel?)
    /// A widget that defines a section header for easier navigation of the
    /// dashboard.
    indirect case sectionHeader(SectionHeader?)
    /// A widget that groups the other widgets by using a dropdown menu.
    indirect case singleViewGroup(SingleViewGroup?)
  }

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