import { _decorator, Component, Node } from 'cc';
import { MainManager } from '../MainManager';
import { UserDataBehaviour } from '../../../data/UserDataBehaviour';
import { SettingsData as GameSettingsData } from '../../../data/DataModel';
import { ManagerType, TopLevelManager } from '../TopLevelManager';
import { IGameDataSaver } from '../../interface/ISaveInfo';
import { SoundManager } from '../../Sound/SoundManager';
const { ccclass, property } = _decorator;

@ccclass('GameSettingsManager')
export class GameSettingsManager extends TopLevelManager implements IGameDataSaver
{
    private mainManager: MainManager;
    private userDataBehaviour: UserDataBehaviour;

    public gameSettingData: GameSettingsData;
    
    public fn_SetUserDataBehaviour()
    {
        this.userDataBehaviour = this.userDataBehaviour == null ? 
                                 this.mainManager.fn_GetMainManager<UserDataBehaviour>(ManagerType.USER_DATA_BEHAVIOUR) : 
                                 this.userDataBehaviour;
    }

    public fn_LoadSavedData() : GameSettingsData
    {
        this.fn_SetUserDataBehaviour();

        this.gameSettingData = this.userDataBehaviour.fn_GetGameSettingData();
        return this.gameSettingData;
    }

    public fn_SaveNewData(data: any)
    {
        this.fn_SetUserDataBehaviour();

        this.gameSettingData = data;
        this.userDataBehaviour.fn_SetGameSettingsData(this.gameSettingData);
    }
    
    public fn_InitMainManager(mainManager: MainManager) 
    {
        this.mainManager = mainManager;
    }
    
    public fn_SetSettingsData(settingsData: GameSettingsData)
    {
    }

    public fn_SendUpdateToSoundManager(data: any)
    {
        let soundManager = this.mainManager.fn_GetMainManager<SoundManager>(ManagerType.SOUND);
        soundManager.fn_UpdateAudios(data);
    }
}

