import Foundation
import UIKit

@objcMembers
public final class LNVAPFacade: NSObject {
    @objc public static func lnMakePlayerView(frame: CGRect) -> LNVAPPlayerView {
        LNVAPPlayerView(frame: frame)
    }

    @objc public static func lnMakeWrapView(frame: CGRect) -> LNVAPWrapView {
        LNVAPWrapView(frame: frame)
    }

    @objc public static func lnUseDefaultLogBridge() {
        // Swift facade keeps log registration centralized through LNVAPLogger.
    }

    @objc(lnRegisterLogHandler:)
    public static func lnRegisterLogHandler(_ handler: @escaping LNVAPLogger.LNLogHandler) {
        LNVAPLogger.registerExternalLog(handler)
    }

    @objc(lnClearLogHandler)
    public static func lnClearLogHandler() {
        LNVAPLogger.clearLogHandler()
    }

    // MARK: - Wrap View Ops (ObjC-friendly façade)

    @objc(lnPlayWrap:filePath:repeatCount:)
    public static func lnPlayWrap(_ wrapView: LNVAPWrapView, filePath: String, repeatCount: Int) {
        wrapView.lnPlay(filePath: filePath, repeatCount: repeatCount)
    }

    @objc(lnPlayWrap:filePath:)
    public static func lnPlayWrap(_ wrapView: LNVAPWrapView, filePath: String) {
        wrapView.lnPlay(filePath: filePath)
    }

    @objc(lnPlayWrap:filePath:repeatCount:delegate:)
    public static func lnPlayWrap(_ wrapView: LNVAPWrapView, filePath: String, repeatCount: Int, delegate: LNVAPWrapPlaybackDelegate?) {
        wrapView.delegate = delegate
        wrapView.lnPlay(filePath: filePath, repeatCount: repeatCount)
    }

    @objc(lnPlayWrap:filePath:delegate:)
    public static func lnPlayWrap(_ wrapView: LNVAPWrapView, filePath: String, delegate: LNVAPWrapPlaybackDelegate?) {
        lnPlayWrap(wrapView, filePath: filePath, repeatCount: 0, delegate: delegate)
    }

    @objc(lnPlayWrapDeprecated:filePath:fps:blendMode:repeatCount:delegate:)
    public static func lnPlayWrapDeprecated(_ wrapView: LNVAPWrapView,
                                            filePath: String,
                                            fps: Int,
                                            blendMode: Int,
                                            repeatCount: Int,
                                            delegate: LNVAPWrapPlaybackDelegate?) {
        wrapView.lnPlayDeprecated(filePath: filePath, fps: fps, blendMode: blendMode, repeatCount: repeatCount, delegate: delegate)
    }

    @objc(lnStopWrap:)
    public static func lnStopWrap(_ wrapView: LNVAPWrapView) {
        wrapView.lnStop()
    }

    @objc(lnPauseWrap:)
    public static func lnPauseWrap(_ wrapView: LNVAPWrapView) {
        wrapView.lnPause()
    }

    @objc(lnResumeWrap:)
    public static func lnResumeWrap(_ wrapView: LNVAPWrapView) {
        wrapView.lnResume()
    }

    @objc(lnSetMuteWrap:mute:)
    public static func lnSetMuteWrap(_ wrapView: LNVAPWrapView, mute: Bool) {
        wrapView.lnSetMute(mute)
    }

    @objc(lnSetWrapContentMode:mode:)
    public static func lnSetWrapContentMode(_ wrapView: LNVAPWrapView, mode: LNVAPWrapContentMode) {
        wrapView.contentModeOption = mode
    }

    @objc(lnGetWrapContentMode:)
    public static func lnGetWrapContentMode(_ wrapView: LNVAPWrapView) -> LNVAPWrapContentMode {
        wrapView.contentModeOption
    }

    @objc(lnSetWrapAutoDestroyAfterFinish:enabled:)
    public static func lnSetWrapAutoDestroyAfterFinish(_ wrapView: LNVAPWrapView, enabled: Bool) {
        wrapView.autoDestroyAfterFinish = enabled
    }

    @objc(lnGetWrapAutoDestroyAfterFinish:)
    public static func lnGetWrapAutoDestroyAfterFinish(_ wrapView: LNVAPWrapView) -> Bool {
        wrapView.autoDestroyAfterFinish
    }

    @objc(lnAddWrapTapGesture:handler:)
    public static func lnAddWrapTapGesture(_ wrapView: LNVAPWrapView, handler: @escaping LNVAPGestureEventBlock) {
        wrapView.lnAddVapTapGesture(handler)
    }

    @objc(lnAddWrapGesture:gesture:callback:)
    public static func lnAddWrapGesture(_ wrapView: LNVAPWrapView, gesture: UIGestureRecognizer, callback: @escaping LNVAPGestureEventBlock) {
        wrapView.lnAddVapGesture(gesture, callback: callback)
    }

    // MARK: - Player View Ops

    @objc(lnPlayPlayer:filePath:repeatCount:)
    public static func lnPlayPlayer(_ playerView: LNVAPPlayerView, filePath: String, repeatCount: Int) {
        playerView.lnPlay(filePath: filePath, repeatCount: repeatCount)
    }

    @objc(lnPlayPlayer:filePath:)
    public static func lnPlayPlayer(_ playerView: LNVAPPlayerView, filePath: String) {
        playerView.lnPlay(filePath: filePath)
    }

    @objc(lnPlayPlayer:filePath:repeatCount:delegate:)
    public static func lnPlayPlayer(_ playerView: LNVAPPlayerView, filePath: String, repeatCount: Int, delegate: LNVAPPlaybackDelegate?) {
        playerView.delegate = delegate
        playerView.lnPlay(filePath: filePath, repeatCount: repeatCount)
    }

    @objc(lnPlayPlayer:filePath:delegate:)
    public static func lnPlayPlayer(_ playerView: LNVAPPlayerView, filePath: String, delegate: LNVAPPlaybackDelegate?) {
        lnPlayPlayer(playerView, filePath: filePath, repeatCount: 0, delegate: delegate)
    }

    @objc(lnPlayPlayerDeprecated:filePath:fps:blendMode:repeatCount:delegate:)
    public static func lnPlayPlayerDeprecated(_ playerView: LNVAPPlayerView,
                                              filePath: String,
                                              fps: Int,
                                              blendMode: Int,
                                              repeatCount: Int,
                                              delegate: LNVAPPlaybackDelegate?) {
        playerView.lnPlayDeprecated(filePath: filePath, fps: fps, blendMode: blendMode, repeatCount: repeatCount, delegate: delegate)
    }

    @objc(lnStopPlayer:)
    public static func lnStopPlayer(_ playerView: LNVAPPlayerView) {
        playerView.lnStop()
    }

    @objc(lnPausePlayer:)
    public static func lnPausePlayer(_ playerView: LNVAPPlayerView) {
        playerView.lnPause()
    }

    @objc(lnResumePlayer:)
    public static func lnResumePlayer(_ playerView: LNVAPPlayerView) {
        playerView.lnResume()
    }

    @objc(lnSetMutePlayer:mute:)
    public static func lnSetMutePlayer(_ playerView: LNVAPPlayerView, mute: Bool) {
        playerView.lnSetMute(mute)
    }

    @objc(lnEnableOldVersionOnPlayer:enable:)
    public static func lnEnableOldVersionOnPlayer(_ playerView: LNVAPPlayerView, enable: Bool) {
        playerView.lnEnableOldVersion(enable)
    }

    @objc(lnSetPlayerFPS:fps:)
    public static func lnSetPlayerFPS(_ playerView: LNVAPPlayerView, fps: Int) {
        playerView.fps = fps
    }

    @objc(lnGetPlayerFPS:)
    public static func lnGetPlayerFPS(_ playerView: LNVAPPlayerView) -> Int {
        playerView.fps
    }

    @objc(lnSetPlayerRenderByOpenGL:enabled:)
    public static func lnSetPlayerRenderByOpenGL(_ playerView: LNVAPPlayerView, enabled: Bool) {
        playerView.renderByOpenGL = enabled
    }

    @objc(lnGetPlayerRenderByOpenGL:)
    public static func lnGetPlayerRenderByOpenGL(_ playerView: LNVAPPlayerView) -> Bool {
        playerView.renderByOpenGL
    }

    @objc(lnSetPlayerEnterBackgroundOperation:operation:)
    public static func lnSetPlayerEnterBackgroundOperation(_ playerView: LNVAPPlayerView, operation: LNEnterBackgroundOperation) {
        playerView.enterBackgroundOperation = operation
    }

    @objc(lnGetPlayerEnterBackgroundOperation:)
    public static func lnGetPlayerEnterBackgroundOperation(_ playerView: LNVAPPlayerView) -> LNEnterBackgroundOperation {
        playerView.enterBackgroundOperation
    }

    @objc(lnGetPlayerCurrentFrame:)
    public static func lnGetPlayerCurrentFrame(_ playerView: LNVAPPlayerView) -> LNMP4AnimatedImageFrame? {
        playerView.lnCurrentFrame
    }

    @objc(lnGetPlayerMP4FilePath:)
    public static func lnGetPlayerMP4FilePath(_ playerView: LNVAPPlayerView) -> String {
        playerView.lnMP4FilePath
    }

    @objc(lnSetPlayerMaskInfo:maskInfo:)
    public static func lnSetPlayerMaskInfo(_ playerView: LNVAPPlayerView, maskInfo: LNVAPMaskInfo?) {
        playerView.maskInfo = maskInfo
    }

    @objc(lnGetPlayerMaskInfo:)
    public static func lnGetPlayerMaskInfo(_ playerView: LNVAPPlayerView) -> LNVAPMaskInfo? {
        playerView.maskInfo
    }

    @objc(lnAddPlayerTapGesture:target:action:)
    public static func lnAddPlayerTapGesture(_ playerView: LNVAPPlayerView, target: Any, action: Selector) {
        playerView.lnAddTapGesture(target: target, action: action)
    }

    @objc(lnAddPlayerVapTapGesture:handler:)
    public static func lnAddPlayerVapTapGesture(_ playerView: LNVAPPlayerView, handler: @escaping LNVAPGestureEventBlock) {
        playerView.lnAddVapTapGesture(handler)
    }

    @objc(lnAddPlayerVapGesture:gesture:callback:)
    public static func lnAddPlayerVapGesture(_ playerView: LNVAPPlayerView, gesture: UIGestureRecognizer, callback: @escaping LNVAPGestureEventBlock) {
        playerView.lnAddVapGesture(gesture, callback: callback)
    }
}
