//
//  PlayerProtocol.swift
//  Pods
//
//  Created by Asti Manuka on 28/11/23.
//

import Foundation
import PRESTOplay

// Common interface for PlayerProxy and ApplePlayerProxy
public protocol PlayerProtocol: AnyObject {
    var id: String { get }

    var delegate: (any PRESTOplay.PlayerAPI)? { get }

    func destroy()
    func open(jsonPlayerConfiguration: [String: Any], completion: @escaping () -> Void) throws -> Void
    func play()
    func replay()
    func pause()
    func stop()
    func skip(intervalMs: Int64)
    func setPosition(_ newPositionMs: Int64)
    func setPlaybackRate(_ newPlaybackRate: Double)
    func getPlaybackRate() -> Double
    func setVolume(_ newVolume: Double)
    func setMuted(_ newMuted: Bool)
    func setAudioTrack(_ trackId: String)
    func setVideoTrack(_ trackId: String)
    func setVideoRendition(_ renditionId: String)
    func setTextTrack(_ trackId: String?)
    func enableAdaptiveVideo()

    func addExtension(playerExtension: PlayerExtension)
    func getExtension<T: PlayerExtension>(of type: T.Type) -> T?

    func supportsPictureInPicture() -> Bool
    func isInPictureInPictureMode() -> Bool
    func enterPictureInPictureMode()
    func exitPictureInPictureMode()

    func attachToView(_ to: UIView)
    func updateSize(_ rect: CGRect)
    func detachFromView()
    
    func getViewController() -> PRESTOplay.PlayerViewControllerAPI?
    func sessionId() -> String
}

