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

import Foundation

public struct DiscoverResp: Codable, Equatable {
    public var page: Int
    public var pageSize: Int
    public var sections: [Section]?
    public var startIndex: Int
    public var totalSections: Int

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

        public enum Object: Codable, Equatable {
            case bannerSectionSchema(BannerSectionSchema)
            case playlistSectionSchema(PlaylistSectionSchema)
            case playlistListSectionSchema(PlaylistListSectionSchema)
            case styleListSectionSchema(StyleListSectionSchema)
            case userListSectionSchema(UserListSectionSchema)
            case communityPersonasSectionSchema(CommunityPersonasSectionSchema)
            case featuredFeedSectionSchema(FeaturedFeedSectionSchema)
            case shortcutSectionSchema(ShortcutSectionSchema)
            case promoSectionSchema(PromoSectionSchema)
            case hooksSectionSchema(HooksSectionSchema)
            case contestListSectionSchema(ContestListSectionSchema)

            public init(from decoder: Decoder) throws {

                struct Discriminator: Decodable {
                    let sectionType: String
                }

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

                switch discriminatorValue {
                case "banner": self = .bannerSectionSchema(try container.decode(BannerSectionSchema.self))
                case "playlist": self = .playlistSectionSchema(try container.decode(PlaylistSectionSchema.self))
                case "playlist_list": self = .playlistListSectionSchema(try container.decode(PlaylistListSectionSchema.self))
                case "style_list": self = .styleListSectionSchema(try container.decode(StyleListSectionSchema.self))
                case "user_list": self = .userListSectionSchema(try container.decode(UserListSectionSchema.self))
                case "persona_list": self = .communityPersonasSectionSchema(try container.decode(CommunityPersonasSectionSchema.self))
                case "featured_feed": self = .featuredFeedSectionSchema(try container.decode(FeaturedFeedSectionSchema.self))
                case "shortcut": self = .shortcutSectionSchema(try container.decode(ShortcutSectionSchema.self))
                case "promo": self = .promoSectionSchema(try container.decode(PromoSectionSchema.self))
                case "hooks": self = .hooksSectionSchema(try container.decode(HooksSectionSchema.self))
                case "contest_list": self = .contestListSectionSchema(try container.decode(ContestListSectionSchema.self))

                default:
                    throw DecodingError.dataCorruptedError(
                        in: container,
                        debugDescription: "Discriminator value '\(discriminatorValue)' does not match any expected values (banner, playlist, playlist_list, style_list, user_list, persona_list, featured_feed, shortcut, promo, hooks, contest_list)."
                    )
                }
            }

            public func encode(to encoder: Encoder) throws {
                var container = encoder.singleValueContainer()
                switch self {
                case .bannerSectionSchema(let value): try container.encode(value)
                case .playlistSectionSchema(let value): try container.encode(value)
                case .playlistListSectionSchema(let value): try container.encode(value)
                case .styleListSectionSchema(let value): try container.encode(value)
                case .userListSectionSchema(let value): try container.encode(value)
                case .communityPersonasSectionSchema(let value): try container.encode(value)
                case .featuredFeedSectionSchema(let value): try container.encode(value)
                case .shortcutSectionSchema(let value): try container.encode(value)
                case .promoSectionSchema(let value): try container.encode(value)
                case .hooksSectionSchema(let value): try container.encode(value)
                case .contestListSectionSchema(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 init(page: Int, pageSize: Int, sections: [Section]? = nil, startIndex: Int, totalSections: Int) {
        self.page = page
        self.pageSize = pageSize
        self.sections = sections
        self.startIndex = startIndex
        self.totalSections = totalSections
    }
}
