//
// Fruit.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif

public enum Fruit: Codable, JSONEncodable, Hashable {
    case typeApple(Apple)
    case typeBanana(Banana)

    public func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        switch self {
        case .typeApple(let value):
            try container.encode(value)
        case .typeBanana(let value):
            try container.encode(value)
        }
    }

    public init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        if let value = try? container.decode(Apple.self) {
            self = .typeApple(value)
        } else if let value = try? container.decode(Banana.self) {
            self = .typeBanana(value)
        } else {
            throw DecodingError.typeMismatch(Self.Type.self, .init(codingPath: decoder.codingPath, debugDescription: "Unable to decode instance of Fruit"))
        }
    }
}

