using UnityEngine;
using DG.Tweening;

public class Basket : MonoBehaviour
{
	public int basketTypeId;
	public string objectLayerId = "object";
	public int positiveScore = 2;
	public int negativeScore = -1;

	private GameManager gameManager;

	private void Awake()
	{
		gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
	}

	private void OnTriggerEnter(Collider other) 
	{
		if (other.gameObject.layer == LayerMask.NameToLayer(objectLayerId))
		{
			var objectData = other.gameObject.GetComponentInParent<ObjectData>();

			if(objectData.objectTypeId == basketTypeId)
			{
				gameManager.AddScore(positiveScore);
			}
			else
			{
				gameManager.AddScore(negativeScore);
			}

			var go = other.gameObject;

			Destroy(other.gameObject.GetComponent<Rigidbody>());
			Destroy(other.gameObject.GetComponent<Collider>());

			other.transform.DOMoveY(40, 0.5f).SetEase(Ease.InQuad).OnComplete(() =>
			{
				Object.Destroy(go);
			});
		}
	}
}
