// Generated by Create API
// https://github.com/CreateAPI/CreateAPI

import Foundation

public struct BannerSectionSchema: Codable, Equatable, Identifiable {
    public var description: String?
    public var id: String
    public var items: [Item]
    public var link: String?
    public var mobileLink: String?
    public var options: [String]?
    public var secondaryOptions: [String]?
    public var secondarySelectedOption: String?
    public var sectionName: String?
    public var sectionType: SectionType?
    public var selectedOption: String?
    public var styleType: String?
    public var title: String

    public struct Item: Codable, Equatable {
        public var object: Object?
        public var anyJSON: AnyJSON?

        public enum Object: Codable, Equatable {
            case bannerMobileAppGraphicSchema(BannerMobileAppGraphicSchema)
            case bannerWebGraphicSchema(BannerWebGraphicSchema)

            public init(from decoder: Decoder) throws {

                struct Discriminator: Decodable {
                    let type: String
                }

                let container = try decoder.singleValueContainer()
                let discriminatorValue = try container.decode(Discriminator.self).type

                switch discriminatorValue {
                case "android": self = .bannerMobileAppGraphicSchema(try container.decode(BannerMobileAppGraphicSchema.self))
                case "ios": self = .bannerMobileAppGraphicSchema(try container.decode(BannerMobileAppGraphicSchema.self))
                case "mobile-web": self = .bannerWebGraphicSchema(try container.decode(BannerWebGraphicSchema.self))
                case "web": self = .bannerWebGraphicSchema(try container.decode(BannerWebGraphicSchema.self))

                default:
                    throw DecodingError.dataCorruptedError(
                        in: container,
                        debugDescription: "Discriminator value '\(discriminatorValue)' does not match any expected values (android, ios, mobile-web, web)."
                    )
                }
            }

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

        public init(object: Object? = nil, anyJSON: AnyJSON? = nil) {
            self.object = object
            self.anyJSON = anyJSON
        }

        public init(from decoder: Decoder) throws {
            let container = try decoder.singleValueContainer()
            self.object = try? container.decode(Object.self)
            self.anyJSON = try? container.decode(AnyJSON.self)
        }

        public func encode(to encoder: Encoder) throws {
            var container = encoder.singleValueContainer()
            if let value = object { try container.encode(value) }
            if let value = anyJSON { try container.encode(value) }
        }
    }

    public struct SectionType: RawRepresentable, Codable, Equatable {
        public let rawValue: String

        public init(rawValue: String) {
            self.rawValue = rawValue
        }

        public static let banner = Self(rawValue: "banner")
    }

    public init(description: String? = nil, id: String, items: [Item], link: String? = nil, mobileLink: String? = nil, options: [String]? = nil, secondaryOptions: [String]? = nil, secondarySelectedOption: String? = nil, sectionName: String? = nil, sectionType: SectionType? = nil, selectedOption: String? = nil, styleType: String? = nil, title: String) {
        self.description = description
        self.id = id
        self.items = items
        self.link = link
        self.mobileLink = mobileLink
        self.options = options
        self.secondaryOptions = secondaryOptions
        self.secondarySelectedOption = secondarySelectedOption
        self.sectionName = sectionName
        self.sectionType = sectionType
        self.selectedOption = selectedOption
        self.styleType = styleType
        self.title = title
    }
}
