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

import Foundation
import Get
import URLQueryEncoder

extension Paths.Billing {
    public var subscriptionDescriptions: SubscriptionDescriptions {
        SubscriptionDescriptions(path: path + "/subscription-descriptions")
    }

    public struct SubscriptionDescriptions {
        /// Path: `/api/billing/subscription-descriptions`
        public let path: String

        /// Get Localized Subscription Descriptions
        ///
        /// Return localized strings for subscription/paywalls within billing.
        /// 
        /// - lang: optional language code (e.g., en, es, fr). If omitted, resolved from Accept-Language.
        /// - surface: one of [web, ios, android]. Defaults to web if not provided and cannot be derived from headers.
        public func get(lang: String? = nil, surface: String? = nil) -> Request<GetResponse> {
            Request(path: path, method: "GET", query: makeGetQuery(lang, surface), id: "studio_api_bots_billing_api_get_localized_subscription_descriptions")
        }

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

            /// Response
            public enum Object: Decodable, Equatable {
                case webBillingLocalizationsResponse(GenAPI.WebBillingLocalizationsResponse)
                case iosBillingLocalizationsResponse(GenAPI.IosBillingLocalizationsResponse)
                case androidBillingLocalizationsResponse(GenAPI.AndroidBillingLocalizationsResponse)

                public init(from decoder: Decoder) throws {

                    struct Discriminator: Decodable {
                        let surface: String
                    }

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

                    switch discriminatorValue {
                    case "web": self = .webBillingLocalizationsResponse(try container.decode(GenAPI.WebBillingLocalizationsResponse.self))
                    case "ios": self = .iosBillingLocalizationsResponse(try container.decode(GenAPI.IosBillingLocalizationsResponse.self))
                    case "android": self = .androidBillingLocalizationsResponse(try container.decode(GenAPI.AndroidBillingLocalizationsResponse.self))

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

            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)
            }
        }

        private func makeGetQuery(_ lang: String?, _ surface: String?) -> [(String, String?)] {
            let encoder = URLQueryEncoder()
            encoder.encode(lang, forKey: "lang")
            encoder.encode(surface, forKey: "surface")
            return encoder.items
        }
    }
}
