/* Copyright (C) Itseez3D, Inc. - All Rights Reserved
* You may not use this file except in compliance with an authorized license
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* UNLESS REQUIRED BY APPLICABLE LAW OR AGREED BY ITSEEZ3D, INC. IN WRITING, SOFTWARE DISTRIBUTED UNDER THE LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED
* See the License for the specific language governing permissions and limitations under the License.
* Written by Itseez3D, Inc. <support@avatarsdk.com>, August 2026
*/

using UnityEngine;

namespace AvatarSDKMove
{
	public class TargetPositionConstraint : MonoBehaviour
	{
		[Header("Target")]
		public Transform target;

		[Header("World Bounds")]
		public Vector3 minBounds = new Vector3(-0.5f, 0.0f, -0.5f);
		public Vector3 maxBounds = new Vector3(0.5f, 2.0f, 0.5f);

		public void UpdateTargetPosition()
		{
			if (target == null)
				return;

			Vector3 position = target.position;
			Vector3 clampedPosition = new Vector3(
				Mathf.Clamp(position.x, minBounds.x, maxBounds.x),
				Mathf.Clamp(position.y, minBounds.y, maxBounds.y),
				Mathf.Clamp(position.z, minBounds.z, maxBounds.z));

			if (clampedPosition == position)
				return;

			target.position = clampedPosition;
		}

		private void OnDrawGizmosSelected()
		{
			Gizmos.color = Color.yellow;
			Gizmos.DrawWireCube((minBounds + maxBounds) * 0.5f, maxBounds - minBounds);
		}
	}
}
