import { _decorator, Component, Node } from 'cc';
import { EventOperations, EventsType, IEventHandler } from '../../interface/IPrimary';
import { EventsManagerNew } from './EventsManagerNew';
import { GameManager } from '../../state/GameManager';
const { ccclass, property } = _decorator;

@ccclass('EventsHandler')
export class EventsHandler extends Component 
{
    private gameManager: GameManager;
    private eventsHandler: IEventHandler;

    public fn_InitGameManager(gameManager: GameManager)
    {
        this.gameManager = gameManager;
    }
    
    public fn_ManageEventOperation(evtOp: EventOperations, evtType: EventsType)
    {
        switch (evtOp)
        {
            case EventOperations.ATTACH:
                EventsManagerNew.fn_AttachNewEvent(evtType, this.fn_GetCurrentEventHandler(evtType));
                break;
            case EventOperations.DETACH:
                EventsManagerNew.fn_DetachEvent(evtType);
                break;
            case EventOperations.FIRE:
                EventsManagerNew.fn_FireEvent(evtType);
                break;
        }
    }
    
    private fn_GetCurrentEventHandler(evtType: EventsType)
    {
        switch (evtType)
        {
            case EventsType.HINT_BAR:
            case EventsType.ARCHIVE_CARDS:
                this.eventsHandler = this.gameManager.m_CardManager as IEventHandler;
                break;
            case EventsType.RETURN_TO_MENU:
                this.eventsHandler = this.gameManager.m_UIManager as IEventHandler;
                break;
            case EventsType.RESTART:
                this.eventsHandler = this.gameManager as IEventHandler;
                break;
        }

        return this.eventsHandler;
    }    
}

