import AVFoundation

/**
 * Everything the decoder needs to start presenting one item.
 *
 * The plain fields describe WHAT to play and are filled by the engine. The
 * two payload slots describe HOW bytes are reached; they start empty and
 * are attached by adapter-layer interceptors (cache, DRM) on the way
 * through the pipeline. They are opaque cargo: only the default AVPlayer
 * decoder interprets them, and a prepared asset supersedes building one
 * from `uri`.
 */
final class DecoderLoadRequest {
    let uri: String
    let headers: [String: String]?
    let startPositionMs: Double?
    let endPositionMs: Double?

    /** Attached by the cache interceptor (resource-loader-backed asset). */
    var preparedAsset: AVURLAsset?

    /**
     * Attached by the DRM interceptor for FairPlay. Must reach the decoder:
     * it has to be registered on the asset before the AVPlayerItem exists.
     */
    var contentKeySession: AVContentKeySession?

    init(uri: String,
         headers: [String: String]? = nil,
         startPositionMs: Double? = nil,
         endPositionMs: Double? = nil)
    {
        self.uri = uri
        self.headers = headers
        self.startPositionMs = startPositionMs
        self.endPositionMs = endPositionMs
    }
}
