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 kLNMP4DefaultFPS = 20
public let kLNMP4MinFPS = 1
public let LNMP4MaxFPS = 60
public let LNVAPMaxCompatibleVersion = 2

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

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