package com.fireworksdk.bridge.utils import com.firework.analyticsevents.VideoInfo import com.firework.analyticsevents.VideoType import com.firework.analyticsevents.cta.CtaButtonClickAnalyticsEvent import com.firework.analyticsevents.player.PlayerLifecycleAnalyticsEvent import com.firework.analyticsevents.player.VideoEngagedEvent import com.firework.analyticsevents.share.ShareButtonAnalyticsEvent import com.firework.common.product.Product import com.fireworksdk.bridge.models.FWLiveStreamEventDetailsModel import com.fireworksdk.bridge.models.FWShoppingCustomCta import com.fireworksdk.bridge.models.FWVideoPlaybackDetails object FWModelUtils { val VideoInfo.internalVideoType: String get() = when (this.videoType) { is VideoType.ShortVideo -> "video" is VideoType.Ad -> "ad" is VideoType.Livestream.Idle -> "livestream" is VideoType.Livestream.Live -> "livestream" is VideoType.Livestream.Replay -> "livestream" is VideoType.Livestream.Completed -> "livestream" } val VideoInfo.internalLiveStreamStatus: String? get() = when (this.videoType) { is VideoType.ShortVideo -> null is VideoType.Ad -> null is VideoType.Livestream.Idle -> "idle" is VideoType.Livestream.Live -> "live" is VideoType.Livestream.Replay -> "replay" is VideoType.Livestream.Completed -> "completed" } fun convertVideoInfo2PlaybackDetails(videoInfo: VideoInfo): FWVideoPlaybackDetails { return FWVideoPlaybackDetails( badge = videoInfo.badge, caption = videoInfo.caption, duration = videoInfo.duration, hasCta = videoInfo.hasCta, hashtags = videoInfo.hashtags, playerHeight = videoInfo.playerHeight, playerWidth = videoInfo.playerWidth, id = videoInfo.id, feedId = videoInfo.feedId, actionUrl = videoInfo.ctaActionUrl, ctaActionType = videoInfo.ctaActionType, videoType = videoInfo.internalVideoType, liveStreamStatus = videoInfo.internalLiveStreamStatus, ) } fun convertVideoInfo2CustomCta(product: Product?): FWShoppingCustomCta? { val url = product?.customCTAUrl val title = product?.customCTATitleTranslation val titleKey = product?.customCTATitle return if (!url.isNullOrBlank() && !titleKey.isNullOrBlank() && !title.isNullOrBlank() && product.isCustomCtaPrimary) { FWShoppingCustomCta( url = url, titleKey = titleKey, title = title, ) } else { null } } fun convertVideoInfo2CustomSecondaryCta(product: Product?): FWShoppingCustomCta? { val url = product?.customCTAUrl val title = product?.customCTATitleTranslation val titleKey = product?.customCTATitle return if (!url.isNullOrBlank() && !titleKey.isNullOrBlank() && !title.isNullOrBlank() && !product.isCustomCtaPrimary) { FWShoppingCustomCta( url = url, titleKey = titleKey, title = title, ) } else { null } } fun convertVideoInfo2LivestreamDetails(videoInfo: VideoInfo): FWLiveStreamEventDetailsModel { return FWLiveStreamEventDetailsModel( id = videoInfo.id, feedId = videoInfo.feedId, videoType = videoInfo.internalVideoType, liveStreamStatus = videoInfo.internalLiveStreamStatus, playbackDetails = convertVideoInfo2PlaybackDetails(videoInfo) ) } fun convertCtaEvent2PlaybackDetails(event: CtaButtonClickAnalyticsEvent): FWVideoPlaybackDetails { return FWVideoPlaybackDetails( badge = event.videoInfo.badge, caption = event.videoInfo.caption, duration = event.videoInfo.duration, hasCta = true, hashtags = event.videoInfo.hashtags, playerHeight = event.videoInfo.playerHeight, playerWidth = event.videoInfo.playerWidth, id = event.videoInfo.id, actionUrl = event.actionUrl, feedId = event.videoInfo.feedId, ctaActionType = event.videoInfo.ctaActionType, videoType = event.videoInfo.internalVideoType, liveStreamStatus = event.videoInfo.internalLiveStreamStatus, ) } fun convertPlayerEvent2PlaybackDetails(event: PlayerLifecycleAnalyticsEvent): FWVideoPlaybackDetails { return FWVideoPlaybackDetails( badge = event.videoInfo?.badge, caption = event.videoInfo?.caption, duration = event.videoInfo?.duration, hasCta = event.videoInfo?.hasCta, hashtags = event.videoInfo?.hashtags, playerHeight = event.videoInfo?.playerHeight, playerWidth = event.videoInfo?.playerWidth, id = event.videoInfo?.id, progress = event.progress, feedId = event.videoInfo?.feedId, actionUrl = event.videoInfo?.ctaActionUrl, ctaActionType = event.videoInfo?.ctaActionType, videoType = event.videoInfo?.internalVideoType, liveStreamStatus = event.videoInfo?.internalLiveStreamStatus, ) } fun convertVideoEngageEvent2PlaybackDetails(event: VideoEngagedEvent) : FWVideoPlaybackDetails { return FWVideoPlaybackDetails( badge = event.videoInfo?.badge, caption = event.videoInfo?.caption, duration = event.videoInfo?.duration, hasCta = event.videoInfo?.hasCta, hashtags = event.videoInfo?.hashtags, playerHeight = event.videoInfo?.playerHeight, playerWidth = event.videoInfo?.playerWidth, id = event.videoInfo?.id, feedId = event.videoInfo?.feedId, actionUrl = event.videoInfo?.ctaActionUrl, ctaActionType = event.videoInfo?.ctaActionType, videoType = event.videoInfo?.internalVideoType, liveStreamStatus = event.videoInfo?.internalLiveStreamStatus, ) } fun convertShareButtonEvent2PlaybackDetails(event: ShareButtonAnalyticsEvent): FWVideoPlaybackDetails { return FWVideoPlaybackDetails( badge = event.videoInfo.badge, caption = event.videoInfo.caption, duration = event.videoInfo.duration, hasCta = event.videoInfo.hasCta, hashtags = event.videoInfo.hashtags, playerHeight = event.videoInfo.playerHeight, playerWidth = event.videoInfo.playerWidth, id = event.videoInfo.id, feedId = event.videoInfo.feedId, actionUrl = event.videoInfo.ctaActionUrl, ctaActionType = event.videoInfo.ctaActionType, videoType = event.videoInfo.internalVideoType, liveStreamStatus = event.videoInfo.internalLiveStreamStatus, ) } }