using Nox.Input;
using System.Collections;
using UnityEngine;
using UnityEngine.AddressableAssets;

namespace Nox.Platform {
    public class UnityEditorPlatform : IPlatform {
        private readonly AssetReference assetReference;
        private UnityEditorPlatformSettings editorPlatformSettings;

        public UnityEditorPlatform(AssetReference assetReference) {
            this.assetReference = assetReference;
        }
        public PlatformSettings PlatformSettings => editorPlatformSettings;
        public IEnumerator Initialize(object applicationData) {
            var handle = Addressables.LoadAssetAsync<UnityEditorPlatformSettings>(assetReference);
            yield return new WaitUntil(() => handle.IsDone);
            editorPlatformSettings = handle.Result;
            Debug.Log($"Device Platform {editorPlatformSettings.devicePlatform} initialized");
            InitializeInput();
        }

        public IInput InitializeInput() {
            var inputHandler = new EditorInput(editorPlatformSettings);
            inputHandler.Initialize();
            return inputHandler;
        }
        public void Tick() { }
        public void Dispose() { }

        public void OnApplicationQuit() { }
    }
}
