import Foundation
import UIKit

public typealias LNVAPImageCompletion = (_ image: UIImage?, _ error: NSError?, _ imageURL: String) -> Void
public typealias LNVAPGestureEventBlock = (_ gestureRecognizer: UIGestureRecognizer, _ insideSource: Bool, _ source: LNVAPSourceDisplayItem?) -> Void

public let kQGHWDMP4DefaultFPS = 20
public let kQGHWDMP4MinFPS = 1
public let QGHWDMP4MaxFPS = 60
public let VapMaxCompatibleVersion = 2

@objc public enum LNTextureBlendMode: Int {
    case alphaLeft = 0
    case alphaRight = 1
    case alphaTop = 2
    case alphaBottom = 3
}

public typealias QGHWDTextureBlendMode = LNTextureBlendMode

@objc public enum LNEnterBackgroundOperation: Int {
    case stop
    case pauseAndResume
    case doNothing

    var legacyRawValue: Int {
        switch self {
        case .stop: return 0
        case .pauseAndResume: return 1
        case .doNothing: return 2
        }
    }
}

@objc public enum LNVAPWrapContentMode: Int {
    case scaleToFill
    case aspectFit
    case aspectFill

    var legacyRawValue: Int {
        switch self {
        case .scaleToFill: return 0
        case .aspectFit: return 1
        case .aspectFill: return 2
        }
    }
}

@objc public protocol LNVAPPlaybackDelegate: AnyObject {
    @objc optional func lnPlayerShouldStart(_ playerView: LNVAPPlayerView, config: LNVAPConfigModel) -> Bool
    @objc optional func lnPlayerDidStart(_ playerView: LNVAPPlayerView)
    @objc optional func lnPlayerDidPlay(_ playerView: LNVAPPlayerView, frame: LNMP4AnimatedImageFrame)
    @objc optional func lnPlayerDidStop(_ playerView: LNVAPPlayerView)
    @objc optional func lnPlayerDidFinish(_ playerView: LNVAPPlayerView, totalFrameCount: Int)
    @objc optional func lnPlayerDidFail(_ playerView: LNVAPPlayerView, error: NSError)
    @objc optional func lnPlayerContent(forTag tag: String, resource: LNVAPSourceInfo) -> String?
    @objc optional func lnPlayerLoadImage(withURL url: String, context: NSDictionary, completion: @escaping LNVAPImageCompletion)
}

@objc public protocol LNVAPLegacyPlaybackDelegate: AnyObject {
    @objc optional func shouldStartPlayMP4(_ container: UIView, config: LNVAPConfigModel) -> Bool
    @objc optional func viewDidStartPlayMP4(_ container: UIView)
    @objc optional func viewDidPlayMP4AtFrame(_ frame: LNMP4AnimatedImageFrame, view container: UIView)
    @objc optional func viewDidStopPlayMP4(_ lastFrameIndex: Int, view container: UIView)
    @objc optional func viewDidFinishPlayMP4(_ totalFrameCount: Int, view container: UIView)
    @objc optional func viewDidFailPlayMP4(_ error: NSError)
    @objc optional func contentForVapTag(_ tag: String, resource: LNVAPSourceInfo) -> String?
    @objc optional func loadVapImage(withURL url: String, context: NSDictionary, completion: @escaping LNVAPImageCompletion)
}

@objc public protocol LNVAPWrapPlaybackDelegate: AnyObject {
    @objc optional func lnWrapViewShouldStart(_ wrapView: LNVAPWrapView, config: LNVAPConfigModel) -> Bool
    @objc optional func lnWrapViewDidStart(_ wrapView: LNVAPWrapView)
    @objc optional func lnWrapViewDidPlay(_ wrapView: LNVAPWrapView, frame: LNMP4AnimatedImageFrame)
    @objc optional func lnWrapViewDidStop(_ wrapView: LNVAPWrapView)
    @objc optional func lnWrapViewDidFinish(_ wrapView: LNVAPWrapView, totalFrameCount: Int)
    @objc optional func lnWrapViewDidFail(_ wrapView: LNVAPWrapView, error: NSError)
    @objc optional func lnWrapViewContent(forTag tag: String, resource: LNVAPSourceInfo) -> String?
    @objc optional func lnWrapViewLoadImage(withURL url: String, context: NSDictionary, completion: @escaping LNVAPImageCompletion)
}

@objc public protocol LNVAPWrapLegacyPlaybackDelegate: AnyObject {
    @objc optional func vapWrap_viewshouldStartPlayMP4(_ container: UIView, config: LNVAPConfigModel) -> Bool
    @objc optional func vapWrap_viewDidStartPlayMP4(_ container: UIView)
    @objc optional func vapWrap_viewDidPlayMP4AtFrame(_ frame: LNMP4AnimatedImageFrame, view container: UIView)
    @objc optional func vapWrap_viewDidStopPlayMP4(_ lastFrameIndex: Int, view container: UIView)
    @objc optional func vapWrap_viewDidFinishPlayMP4(_ totalFrameCount: Int, view container: UIView)
    @objc optional func vapWrap_viewDidFailPlayMP4(_ error: NSError)
    @objc optional func vapWrapview_contentForVapTag(_ tag: String, resource: LNVAPSourceInfo) -> String?
    @objc optional func vapWrapView_loadVapImage(withURL url: String, context: NSDictionary, completion: @escaping LNVAPImageCompletion)
}
