import BaseMachine from 'src/slotMachines/BaseMachine';
import { WinLineRecord, WinsData } from 'src/types/WinsData';
import BaseSystem from '../systems/BaseSystem';

export default class SetCurrentWinLinesSystem extends BaseSystem
{
    public state: string = 'stopped';

    static override requiredInputs: string[] = ['wins'];
    static override sharedSystemData: string[] = ['animateLines', 'currentWinIndex'];

    constructor(machine: BaseMachine)
    {
        super(machine);
    }

    override onEnter()
    {
        this.handleWinsData();
    }

    override update(_dt: number)
    {
    // do nothing
    }

    override onLeave()
    {
    // Do nothing
    }

    private handleWinsData()
    {
        const winsData: WinsData = this.machine.inputs.wins;
        const currentWinIndex = this.machine.sharedSystemData.currentWinIndex;
        const win: WinLineRecord = winsData.wins[currentWinIndex];

        this.machine.sharedSystemData.animateLines.push(win.lineIndex);
    }
}
