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

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

    static override requiredMaps: string[] = ['winningSymbols'];
    static override requiredInputs: string[] = ['wins'];
    static override sharedSystemData: string[] = ['currentWinIndex'];

    override onEnter()
    {
        if (!this.machine.inputs.wins) return;
        this.processWinMap();
    }

    override onLeave()
    {
    // Do nothing
    }

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

    private processWinMap()
    {
        const currentWinIndex = this.machine.sharedSystemData.currentWinIndex;
        const winsData: WinsData = this.machine.inputs.wins;
        const currentWinData: WinLineRecord = winsData.wins[currentWinIndex];
        const symbolsMap: number[] = currentWinData.lineSlotsIndexMap;

        symbolsMap.forEach((slotIndex: number, reel: number) =>
        {
            const mapIndex = this.machine.utils.grid.fromCRtoMapIndex(reel, slotIndex);

            this.machine.maps.winningSymbols[mapIndex] = true;
        });
    }
}
