//
// Copyright 2020 Swiftkube Project
//
// 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
//
// http://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.
//

///
/// Generated by Swiftkube:ModelGen
/// Kubernetes v1.20.9
/// core.v1.SecretKeySelector
///

import Foundation

public extension core.v1 {

	///
	/// SecretKeySelector selects a key of a Secret.
	///
	struct SecretKeySelector: KubernetesResource {
		///
		/// The key of the secret to select from.  Must be a valid secret key.
		///
		public var key: String
		///
		/// Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
		///
		public var name: String?
		///
		/// Specify whether the Secret or its key must be defined
		///
		public var optional: Bool?
		///
		/// Default memberwise initializer
		///
		public init(
			key: String,
			name: String? = nil,
			optional: Bool? = nil
		) {
			self.key = key
			self.name = name
			self.optional = optional
		}
	}
}

///
/// Codable conformance
///
public extension core.v1.SecretKeySelector {

	private enum CodingKeys: String, CodingKey {

		case key = "key"
		case name = "name"
		case optional = "optional"
	}

	init(from decoder: Decoder) throws {
		let container = try decoder.container(keyedBy: CodingKeys.self)
		self.key = try container.decode(String.self, forKey: .key)
		self.name = try container.decodeIfPresent(String.self, forKey: .name)
		self.optional = try container.decodeIfPresent(Bool.self, forKey: .optional)
	}

	func encode(to encoder: Encoder) throws {
		var encodingContainer = encoder.container(keyedBy: CodingKeys.self)

		try encodingContainer.encode(key, forKey: .key)
		try encodingContainer.encode(name, forKey: .name)
		try encodingContainer.encode(optional, forKey: .optional)
	}
}
