import NullNetwork from './NullNetwork';

/** Mock network that replays pre-recorded responses for testing. */
export default class MockNetwork extends NullNetwork
{
    public override name = 'MockNetwork';
    private pool: unknown[];

    constructor(pool: unknown[])
    {
        super();
        this.pool = pool;
    }

    public override get baseAssetsUrl(): string
    {
        return './';
    }

    public override async init(): Promise<unknown>
    {
        return new Promise((resolve) =>
        {
            setTimeout(() =>
            {
                resolve(this.pool.shift());
            }, 1000);
        });
    }

    public override async heartBeat(): Promise<unknown>
    {
        return new Promise((resolve) =>
        {
            setTimeout(() => resolve({}), 25);
        });
    }

    public override async bet(): Promise<unknown>
    {
        // eslint-disable-next-line no-console
        console.log('MockNetwork.bet', this.pool[0]);

        return new Promise((resolve) =>
        {
            setTimeout(() =>
            {
                resolve(this.pool.shift());
            }, 500);
        });
    }

    public override async freespin(): Promise<unknown>
    {
        return new Promise((resolve) =>
        {
            setTimeout(() => resolve(this.pool.shift()), 25);
        });
    }

    public override async respin(): Promise<unknown>
    {
        return new Promise((resolve) =>
        {
            setTimeout(() => resolve(this.pool.shift()), 25);
        });
    }
}
