import { assert } from "../../../core/assert.js";

const sample = new Float64Array(1024);

export class AnimationTrackBinding {
    /**
     *
     * @type {BoundValueWriter|null}
     */
    writer = null

    /**
     *
     * @type {AnimationTrack}
     */
    track = null

    /**
     *
     * @param {BoundValueWriter} writer
     * @param {AnimationTrack} track
     * @returns {AnimationTrackBinding}
     */
    static from(writer, track) {
        assert.defined(writer,'writer');
        assert.isObject(writer,'writer');
        assert.notNull(writer,'writer');
        assert.equal(writer.isBoundValueWriter,true,'writer.isBoundValueWriter !== true');

        assert.defined(track,'track');
        assert.isObject(track,'track');
        assert.notNull(track,'track');
        assert.equal(track.isAnimationTrack,true,'track.isAnimationTrack !== true');


        const r = new AnimationTrackBinding();

        r.writer = writer;
        r.track = track;

        return r;

    }

    /**
     *
     * @param {number} time
     */
    writeAt(time) {
        this.track.sample(sample, 0, time);

        this.writer.write(sample);
    }
}