const {EVENT_NAMES} = require("./../enums/enums")
const { subscribe } = require("./../canprsr")
const rpmMax = 10000;
const speedMax = 300;
const gearsMax = 6;

const init = (window) => {
    subscribe((data) => {
        switch (data.name) {
            case 'vss':
                window.send(EVENT_NAMES.TELEMETRY_SPEED, data)
                break;
            case 'speed':
                window.send(EVENT_NAMES.TELEMETRY_SPEED, data)
                break;
            case 'rpm':
                window.send(EVENT_NAMES.TELEMETRY_RPM, data)
                break;
            case 'throttlepos':
                window.send(EVENT_NAMES.TELEMETRY_THROTTLE, data)
                break;
            case 'brakeposition':
                window.send(EVENT_NAMES.TELEMETRY_BREAK, data)
                break;
            case 'gear':
                window.send(EVENT_NAMES.TELEMETRY_GEAR, data)
                break;
            default:
                break;
        }
    })
    // setInterval(() => window.send(EVENT_NAMES.TELEMETRY_SPEED, {current: Math.floor(Math.random() * speedMax), max: speedMax}), 1000);
    // window.send(EVENT_NAMES.TELEMETRY_SPEED_MAX, rpmMax);
    // setInterval(() => window.send(EVENT_NAMES.TELEMETRY_RPM, {current: Math.floor(Math.random() * rpmMax), max: rpmMax}), 300);
    // window.send(EVENT_NAMES.TELEMETRY_RPM_MAX, rpmMax);
    // setInterval(() => window.send(EVENT_NAMES.TELEMETRY_THROTTLE, Math.floor(Math.random() * 100)), 300);
    // setInterval(() => window.send(EVENT_NAMES.TELEMETRY_BREAK, Math.floor(Math.random() * 100)), 300);
    // setInterval(() => window.send(EVENT_NAMES.TELEMETRY_GEAR, {current: Math.floor(Math.random() * gearsMax), max: gearsMax}), 500);
    // window.send(EVENT_NAMES.TELEMETRY_GEAR_MAX, gearsMax);


}

module.exports = init;
