import { TimeMgr } from '@common/TimeMgr';

describe('TimeMgr', () => {
    let tm: TimeMgr;
    beforeEach(() => {
        tm = new TimeMgr();
    });

    it('advances both clocks at timeScale 1', () => {
        tm.update(1);
        tm.update(0.5);
        expect(tm.gameTime).toBeCloseTo(1.5);
        expect(tm.realTime).toBeCloseTo(1.5);
    });

    it('freezes gameTime when paused but keeps realTime ticking', () => {
        tm.pause();
        tm.update(1);
        expect(tm.gameTime).toBe(0);
        expect(tm.realTime).toBe(1);
        tm.resume();
        tm.update(0.5);
        expect(tm.gameTime).toBeCloseTo(0.5);
        expect(tm.realTime).toBeCloseTo(1.5);
    });

    it('honors timeScale for slow-mo', () => {
        tm.setTimeScale(0.5);
        tm.update(2);
        expect(tm.gameTime).toBeCloseTo(1);
        expect(tm.realTime).toBe(2);
    });

    it('clamps negative timeScale to 0', () => {
        tm.setTimeScale(-3);
        expect(tm.timeScale).toBe(0);
        tm.update(10);
        expect(tm.gameTime).toBe(0);
    });

    it('scaledDelta() reflects pause and timeScale', () => {
        tm.setTimeScale(2);
        expect(tm.scaledDelta(0.1)).toBeCloseTo(0.2);
        tm.pause();
        expect(tm.scaledDelta(0.1)).toBe(0);
    });

    it('reset() zeros everything', () => {
        tm.update(1);
        tm.pause();
        tm.setTimeScale(0.2);
        tm.reset();
        expect(tm.gameTime).toBe(0);
        expect(tm.realTime).toBe(0);
        expect(tm.timeScale).toBe(1);
        expect(tm.paused).toBe(false);
    });
});
