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

import Foundation
import Get
import URLQueryEncoder

extension Paths.Discover.Sections {
    public func sectionName(_ sectionName: String) -> WithSectionName {
        WithSectionName(path: "\(path)/\(sectionName)")
    }

    public struct WithSectionName {
        /// Path: `/api/discover/sections/{section_name}`
        public let path: String

        /// Get Discover Sections
        ///
        /// Api get request for 'Discover' section of Homepage
        public var get: Request<GetResponse> {
            Request(path: path, method: "GET", id: "studio_api_discover_api_get_discover_sections")
        }

        /// Response
        public struct GetResponse: Decodable, Equatable {
            /// Response
            public var object: Object?
            public var anyJSON: AnyJSON?

            /// Response
            public enum Object: Decodable, Equatable {
                case bannerSectionSchema(GenAPI.BannerSectionSchema)
                case playlistSectionSchema(GenAPI.PlaylistSectionSchema)
                case playlistListSectionSchema(GenAPI.PlaylistListSectionSchema)
                case styleListSectionSchema(GenAPI.StyleListSectionSchema)
                case userListSectionSchema(GenAPI.UserListSectionSchema)
                case communityPersonasSectionSchema(GenAPI.CommunityPersonasSectionSchema)
                case featuredFeedSectionSchema(GenAPI.FeaturedFeedSectionSchema)
                case shortcutSectionSchema(GenAPI.ShortcutSectionSchema)
                case promoSectionSchema(GenAPI.PromoSectionSchema)
                case hooksSectionSchema(GenAPI.HooksSectionSchema)
                case contestListSectionSchema(GenAPI.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(GenAPI.BannerSectionSchema.self))
                    case "playlist": self = .playlistSectionSchema(try container.decode(GenAPI.PlaylistSectionSchema.self))
                    case "playlist_list": self = .playlistListSectionSchema(try container.decode(GenAPI.PlaylistListSectionSchema.self))
                    case "style_list": self = .styleListSectionSchema(try container.decode(GenAPI.StyleListSectionSchema.self))
                    case "user_list": self = .userListSectionSchema(try container.decode(GenAPI.UserListSectionSchema.self))
                    case "persona_list": self = .communityPersonasSectionSchema(try container.decode(GenAPI.CommunityPersonasSectionSchema.self))
                    case "featured_feed": self = .featuredFeedSectionSchema(try container.decode(GenAPI.FeaturedFeedSectionSchema.self))
                    case "shortcut": self = .shortcutSectionSchema(try container.decode(GenAPI.ShortcutSectionSchema.self))
                    case "promo": self = .promoSectionSchema(try container.decode(GenAPI.PromoSectionSchema.self))
                    case "hooks": self = .hooksSectionSchema(try container.decode(GenAPI.HooksSectionSchema.self))
                    case "contest_list": self = .contestListSectionSchema(try container.decode(GenAPI.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 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)
            }
        }
    }
}
