/**
 * The blend math an adapter performs. Read by higher-level wiring to
 * decide whether the adapter is compatible with the current rendering
 * pipeline.
 *
 * @readonly
 * @enum {number}
 */
export const InterpolationKind = Object.freeze({
    /** No blending — output is one of the two snapshots exactly. */
    Discrete: 0,
    /** Linear blend at fractional `t ∈ [0, 1]` between two snapshots. */
    Linear: 1,
    /** Cubic between four samples. Reserved; not yet supported. */
    Cubic: 2,
});

/**
 * Per-component-type interpolator: reads two encoded snapshots of one
 * component from `source`, blends by `t`, writes the result to
 * `out_buffer` in the SAME wire format so the receiver can deserialize
 * directly via the corresponding `BinaryClassSerializationAdapter`.
 *
 * Pair with {@link InterpolationLog}, which resolves
 * `(network_id, type_id, tick) → byte offset` so the adapter only sees
 * offsets.
 *
 * Subclasses override `kind` if their blend math is non-linear; the
 * default is `Linear`.
 *
 * @author Alex Goldring
 * @copyright Company Named Limited (c) 2026
 */
export class BinaryInterpolationAdapter {

    /** @type {number} one of {@link InterpolationKind} */
    kind = InterpolationKind.Linear;

    /**
     * Advance `out_buffer.position` past the bytes written. `source.position`
     * may be mutated freely (the log restores it).
     *
     * `first_offset === second_offset` is the degenerate "snap to single
     * snapshot" case — implementations don't need to special-case it; the
     * blend at any `t` reduces to the input.
     *
     * @param {BinaryBuffer} out_buffer
     * @param {BinaryBuffer} source
     * @param {number} first_offset byte position of snapshot A
     * @param {number} second_offset byte position of snapshot B
     * @param {number} t blend fraction in [0, 1]; 0 ⇒ A, 1 ⇒ B
     */
    interpolate(out_buffer, source, first_offset, second_offset, t) {
        throw new Error('BinaryInterpolationAdapter subclasses must override interpolate(out, src, off_a, off_b, t).');
    }
}
