import APIClient
import ComposableArchitecture
import StatsigClient
import SwiftUI

public struct Lyrics: Equatable {
    public enum DisplayStyle {
        case none
        case fallback
        case streamed
        case complete
    }

    public var shouldContinuePolling = true
    public var alignedLyrics = [[AlignedLyric]]()
    public var timedLyrics: [LyricsAppearance.TimedLyric]
    public var lyricTime: TimeInterval?

    public var isProcessingLyrics: Bool = false
    public var shouldUseScrollView: Bool = false

    // cachedLyricsAppearanceMap is used externally to render lyrics into SwiftUI View
    public var cachedLyricsAppearanceMap: LyricsAppearance.CacheMap = .empty

    // Display style is local only to internally process
    // the lyrics to stop from unnecessary redraws.
    public var displayStyle: Lyrics.DisplayStyle = .none

    // lyricsRenderProxy is used externally to force rerender the lyrics view
    // This avoids in progress animations from showing up when switching views
    public var renderProxy: Int = .zero

    public init(
        shouldContinuePolling: Bool = true,
        alignedLyrics: [[AlignedLyric]] = [],
        timedLyrics: [LyricsAppearance.TimedLyric],
        lyricTime: TimeInterval? = nil,
        isProcessingLyrics: Bool = false,
        shouldUseScrollView: Bool = false,
        cachedLyricsAppearanceMap: LyricsAppearance.CacheMap = .empty,
        displayStyle: Lyrics.DisplayStyle = .none,
        renderProxy: Int = .zero
    ) {
        self.shouldContinuePolling = shouldContinuePolling
        self.alignedLyrics = alignedLyrics
        self.timedLyrics = timedLyrics
        self.lyricTime = lyricTime
        self.isProcessingLyrics = isProcessingLyrics
        self.shouldUseScrollView = shouldUseScrollView
        self.cachedLyricsAppearanceMap = cachedLyricsAppearanceMap
        self.displayStyle = displayStyle
        self.renderProxy = renderProxy
    }
}
