package com.suno.android.common_data.mappers.cms import com.suno.android.common_core_utils.model.Url import com.suno.android.common_networking.remote.entities.BadgeSchema import com.suno.android.common_networking.remote.entities.BillingPeriodToggleSchema import com.suno.android.common_networking.remote.entities.CountdownSchema import com.suno.android.common_networking.remote.entities.FeatureComparisonSchema import com.suno.android.common_networking.remote.entities.FeatureSchema import com.suno.android.common_networking.remote.entities.FeatureValueSchema import com.suno.android.common_networking.remote.entities.PlanSchema import com.suno.android.common_networking.remote.entities.PlanStickerSchema import com.suno.android.common_networking.remote.entities.PlansSchema import com.suno.android.common_networking.remote.entities.SubscriptionPageCmsSchema import com.suno.android.common_networking.remote.entities.TextSchema import java.time.Instant data class SubscriptionPageCmsContent( val countdown: CountdownContent?, val salesBadge: BadgeContent?, val billingPeriodToggle: BillingPeriodToggleContent?, val plans: PlansContent?, val featureComparison: FeatureComparisonContent?, val language: String?, ) data class BadgeContent( val text: String?, val backgroundColor: String?, val textColor: String?, ) data class CountdownContent( val text: String, val timestamp: Instant, ) data class TextContent( val text: String?, ) data class BillingPeriodToggleContent( val monthlyLabel: TextContent?, val annualLabel: TextContent?, val discountBadge: BadgeContent?, ) data class PlanStickerContent( val monthly: Url?, val annual: Url?, ) data class PlanContent( val displayName: TextContent?, val tagline: TextContent?, val highlightFeatures: List?, val ctaPrimary: TextContent?, val badge: BadgeContent?, val stickers: PlanStickerContent?, ) data class PlansContent( val pro: PlanContent?, val free: PlanContent?, val premier: PlanContent?, ) { fun getPlan( key: String, ): PlanContent? = when (key.lowercase()) { "pro" -> pro "free" -> free "premier" -> premier else -> null } } data class FeatureValueContent( val text: String?, val icon: String?, ) data class FeatureContent( val featureName: TextContent?, val values: List?, ) data class FeatureComparisonContent( val sectionHeader: TextContent?, val features: List?, ) fun SubscriptionPageCmsSchema.toSubscriptionPageCmsContent(): SubscriptionPageCmsContent = SubscriptionPageCmsContent( salesBadge = this.content?.salesBadge?.toBadgeContent(), billingPeriodToggle = this.content?.billingPeriodToggle?.toBillingPeriodToggleContent(), plans = this.content?.plans?.toPlansContent(), featureComparison = this.content?.featureComparison?.toFeatureComparisonContent(), language = this.language, countdown = this.content?.countdown?.toCountdownContent(), ) fun BillingPeriodToggleSchema.toBillingPeriodToggleContent(): BillingPeriodToggleContent = BillingPeriodToggleContent( monthlyLabel = this.monthlyLabel?.toTextContent(), annualLabel = this.annualLabel?.toTextContent(), discountBadge = this.discountBadge?.toBadgeContent(), ) fun PlanSchema.toPlanContent(): PlanContent = PlanContent( displayName = this.displayName?.toTextContent(), tagline = this.tagline?.toTextContent(), highlightFeatures = this.highlightFeatures, ctaPrimary = this.ctaPrimary?.toTextContent(), badge = this.badge?.toBadgeContent(), stickers = this.stickers?.toPlanStickerContent(), ) fun PlansSchema.toPlansContent(): PlansContent = PlansContent( pro = this.pro?.toPlanContent(), free = this.free?.toPlanContent(), premier = this.premier?.toPlanContent(), ) fun FeatureValueSchema.toFeatureValueContent(): FeatureValueContent = FeatureValueContent( text = this.text, icon = this.icon, ) fun FeatureSchema.toFeatureContent(): FeatureContent = FeatureContent( featureName = this.featureName?.toTextContent(), values = this.values?.map { it.toFeatureValueContent() }, ) fun FeatureComparisonSchema.toFeatureComparisonContent(): FeatureComparisonContent = FeatureComparisonContent( sectionHeader = this.sectionHeader?.toTextContent(), features = this.features?.map { it.toFeatureContent() }, ) fun PlanStickerSchema.toPlanStickerContent(): PlanStickerContent = PlanStickerContent( monthly = this.monthly?.let { Url(it) }, annual = this.annual?.let { Url(it) }, ) fun BadgeSchema.toBadgeContent(): BadgeContent = BadgeContent( text = this.text, backgroundColor = this.backgroundColor, textColor = this.textColor, ) fun CountdownSchema.toCountdownContent(): CountdownContent? = try { val text = this.text val timestamp = this.timestamp if (text != null && timestamp != null) { CountdownContent( text = text, timestamp = Instant.parse(timestamp), ) } else { null } } catch (exception: Exception) { null } fun TextSchema.toTextContent(): TextContent = TextContent( text = this.text, )