using System;
using UniRx;
using UnityEngine;
using Random = UnityEngine.Random;

namespace Nan.Scripts
{
    public class Enemy1 : MonoBehaviour
    {
        [SerializeField] private EnemyStatus _enemyStatus;
        [SerializeField] private GameObject _bomb;

        private readonly Subject<Unit> _died = new Subject<Unit>();

        public PlayerControl PlayerControl { get; set; }
        public IObservable<Unit> OnDied { get { return _died; } }

        public void Start()
        {
            _enemyStatus.Hp = 1; //Mathf.Pow(1.1f, ScoreManager.Instance.CurrentLayer);
        }


        private void OnCollisionEnter2D(Collision2D other)
        {
            if (other.gameObject.GetComponent<PlayerBullet>() == null) return;
            _enemyStatus.Hp -= 0.3f;
            if (!(_enemyStatus.Hp < 0)) return;

            var pos = transform.position;
            var bomb = Instantiate(_bomb);
            bomb.transform.position = pos;

            ScoreManager.Instance.AddScore(500, transform.position);
            Destroy(gameObject);
        }
    }
}
