// Copyright (c) coherence ApS.
// For all coherence generated code, the coherence SDK license terms apply. See the license file in the coherence Package root folder for more information.

// <auto-generated>
// Generated file. DO NOT EDIT!
// </auto-generated>
namespace Coherence.Generated
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using UnityEngine;
	using Coherence.Toolkit;
	using Coherence.Toolkit.Bindings;
	using Coherence.Entity;
	using Coherence.ProtocolDef;
	using Coherence.Brook;
	using Coherence.Toolkit.Bindings.ValueBindings;
	using Coherence.Toolkit.Bindings.TransformBindings;
	using Coherence.Connection;
	using Coherence.Log;
	using Logger = Coherence.Log.Logger;
	using UnityEngine.Scripting;

	public class Binding_759334206ec3a2d46b848ec8d2431208_aed3d8b1_439e_4f59_80f0_bae89264c48c : FloatBinding
	{
		private HotPotatoManager CastedUnityComponent;		

		protected override void OnBindingCloned()
		{
			CastedUnityComponent = (HotPotatoManager)UnityComponent;
		}
		public override string CoherenceComponentName => "MiniGameManager_HotPotatoManager_8222345003895092174";

		public override uint FieldMask => 0b00000000000000000000000000000001;

		public override float Value
		{
			get => (float)(System.Single)(CastedUnityComponent.Timer);
			set => CastedUnityComponent.Timer = (System.Single)(value);
		}

		protected override float ReadComponentData(ICoherenceComponentData coherenceComponent)
		{
			var update = (MiniGameManager_HotPotatoManager_8222345003895092174)coherenceComponent;
			return update.Timer;
		}
		
		public override ICoherenceComponentData WriteComponentData(ICoherenceComponentData coherenceComponent)
		{
			var update = (MiniGameManager_HotPotatoManager_8222345003895092174)coherenceComponent;
			update.Timer = Value;
			return update;
		}

		public override ICoherenceComponentData CreateComponentData()
		{
			return new MiniGameManager_HotPotatoManager_8222345003895092174();
		}
	}

	public class Binding_759334206ec3a2d46b848ec8d2431208_a9c999e1_b6d5_4940_ae1b_57306a515589 : IntBinding
	{
		private HotPotatoManager CastedUnityComponent;		

		protected override void OnBindingCloned()
		{
			CastedUnityComponent = (HotPotatoManager)UnityComponent;
		}
		public override string CoherenceComponentName => "MiniGameManager_HotPotatoManager_8222345003895092174";

		public override uint FieldMask => 0b00000000000000000000000000000010;

		public override int Value
		{
			get => (int)(System.Int32)(CastedUnityComponent.CurrentPlayer);
			set => CastedUnityComponent.CurrentPlayer = (System.Int32)(value);
		}

		protected override int ReadComponentData(ICoherenceComponentData coherenceComponent)
		{
			var update = (MiniGameManager_HotPotatoManager_8222345003895092174)coherenceComponent;
			return update.CurrentPlayer;
		}
		
		public override ICoherenceComponentData WriteComponentData(ICoherenceComponentData coherenceComponent)
		{
			var update = (MiniGameManager_HotPotatoManager_8222345003895092174)coherenceComponent;
			update.CurrentPlayer = Value;
			return update;
		}

		public override ICoherenceComponentData CreateComponentData()
		{
			return new MiniGameManager_HotPotatoManager_8222345003895092174();
		}
	}

	public class Binding_759334206ec3a2d46b848ec8d2431208_173fae32_0a65_4ab0_a3c4_f15a43934897 : FloatBinding
	{
		private HotPotatoManager CastedUnityComponent;		

		protected override void OnBindingCloned()
		{
			CastedUnityComponent = (HotPotatoManager)UnityComponent;
		}
		public override string CoherenceComponentName => "MiniGameManager_HotPotatoManager_8222345003895092174";

		public override uint FieldMask => 0b00000000000000000000000000000100;

		public override float Value
		{
			get => (float)(System.Single)(CastedUnityComponent.MaxTime);
			set => CastedUnityComponent.MaxTime = (System.Single)(value);
		}

		protected override float ReadComponentData(ICoherenceComponentData coherenceComponent)
		{
			var update = (MiniGameManager_HotPotatoManager_8222345003895092174)coherenceComponent;
			return update.MaxTime;
		}
		
		public override ICoherenceComponentData WriteComponentData(ICoherenceComponentData coherenceComponent)
		{
			var update = (MiniGameManager_HotPotatoManager_8222345003895092174)coherenceComponent;
			update.MaxTime = Value;
			return update;
		}

		public override ICoherenceComponentData CreateComponentData()
		{
			return new MiniGameManager_HotPotatoManager_8222345003895092174();
		}
	}


	[Preserve]
	[AddComponentMenu("coherence/Baked/Baked 'MiniGameManager' (auto assigned)")]
	[RequireComponent(typeof(CoherenceSync))]
	public class CoherenceSyncMiniGameManager : CoherenceSyncBaked
	{
		private CoherenceSync coherenceSync;
		private Logger logger;

		// Cached targets for commands

		private IClient client;
		private CoherenceMonoBridge monoBridge => coherenceSync.MonoBridge;

		protected void Awake()
		{
			coherenceSync = GetComponent<CoherenceSync>();
			coherenceSync.usingReflection = false;

			logger = coherenceSync.logger.With<CoherenceSyncMiniGameManager>();
			if (coherenceSync.TryGetBindingByGuid("aed3d8b1-439e-4f59-80f0-bae89264c48c", "Timer", out Binding InternalMiniGameManager_HotPotatoManager_8222345003895092174_MiniGameManager_HotPotatoManager_8222345003895092174_Timer))
			{
				var clone = new Binding_759334206ec3a2d46b848ec8d2431208_aed3d8b1_439e_4f59_80f0_bae89264c48c();
				InternalMiniGameManager_HotPotatoManager_8222345003895092174_MiniGameManager_HotPotatoManager_8222345003895092174_Timer.CloneTo(clone);
				coherenceSync.Bindings[coherenceSync.Bindings.IndexOf(InternalMiniGameManager_HotPotatoManager_8222345003895092174_MiniGameManager_HotPotatoManager_8222345003895092174_Timer)] = clone;
			}
			else
			{
				logger.Error("Couldn't find binding (HotPotatoManager).Timer");
			}
			if (coherenceSync.TryGetBindingByGuid("a9c999e1-b6d5-4940-ae1b-57306a515589", "CurrentPlayer", out Binding InternalMiniGameManager_HotPotatoManager_8222345003895092174_MiniGameManager_HotPotatoManager_8222345003895092174_CurrentPlayer))
			{
				var clone = new Binding_759334206ec3a2d46b848ec8d2431208_a9c999e1_b6d5_4940_ae1b_57306a515589();
				InternalMiniGameManager_HotPotatoManager_8222345003895092174_MiniGameManager_HotPotatoManager_8222345003895092174_CurrentPlayer.CloneTo(clone);
				coherenceSync.Bindings[coherenceSync.Bindings.IndexOf(InternalMiniGameManager_HotPotatoManager_8222345003895092174_MiniGameManager_HotPotatoManager_8222345003895092174_CurrentPlayer)] = clone;
			}
			else
			{
				logger.Error("Couldn't find binding (HotPotatoManager).CurrentPlayer");
			}
			if (coherenceSync.TryGetBindingByGuid("173fae32-0a65-4ab0-a3c4-f15a43934897", "MaxTime", out Binding InternalMiniGameManager_HotPotatoManager_8222345003895092174_MiniGameManager_HotPotatoManager_8222345003895092174_MaxTime))
			{
				var clone = new Binding_759334206ec3a2d46b848ec8d2431208_173fae32_0a65_4ab0_a3c4_f15a43934897();
				InternalMiniGameManager_HotPotatoManager_8222345003895092174_MiniGameManager_HotPotatoManager_8222345003895092174_MaxTime.CloneTo(clone);
				coherenceSync.Bindings[coherenceSync.Bindings.IndexOf(InternalMiniGameManager_HotPotatoManager_8222345003895092174_MiniGameManager_HotPotatoManager_8222345003895092174_MaxTime)] = clone;
			}
			else
			{
				logger.Error("Couldn't find binding (HotPotatoManager).MaxTime");
			}
		}

		public override List<ICoherenceComponentData> CreateEntity()
		{
			if (coherenceSync.UsesLODsAtRuntime && (Archetypes.IndexForName.TryGetValue(coherenceSync.Archetype.ArchetypeName, out int archetypeIndex)))
			{
				var components = new List<ICoherenceComponentData>()
				{
					new ArchetypeComponent
					{
						index = archetypeIndex
					}
				};

				return components;
			}
			else
			{
				logger.Warning($"Unable to find archetype {coherenceSync.Archetype.ArchetypeName} in dictionary. Please, bake manually (coherence > Bake)");
			}

			return null;
		}

		public override void Initialize(CoherenceSync sync, IClient client)
		{
			if (coherenceSync == null)
			{
				coherenceSync = sync;
			}
			this.client = client;
		}

		public override void ReceiveCommand(IEntityCommand command)
		{
			switch(command)
			{
				default:
					logger.Warning($"[CoherenceSyncMiniGameManager] Unhandled command: {command.GetType()}.");
					break;
			}
		}
	}
}
