using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace DuckHunter
{
    public class AudioManager : MonoBehaviour
    {
        private static AudioManager _Instance;
        public static AudioManager Instance
        {
            get
            {
                if (!_Instance) new GameObject(typeof(AudioManager).Name).AddComponent<AudioManager>();
                return _Instance;
            }
        }

        void Awake()
        {
            _Instance = this;
        }

        void OnDestroy()
        {
            if (_Instance == this) _Instance = null;
        }

        public void PlayShoot(GameObject target)
        {
            PlayAudio("DuckHunter/Audios/Shoot", GetAudioSource(target));
        }

        public void PlayDuckHit(GameObject target)
        {
            PlayAudio("DuckHunter/Audios/DuckHit", GetAudioSource(target));
        }

        public void PlayDogTaunt(GameObject target)
        {
            PlayAudio("DuckHunter/Audios/DogTaunt", GetAudioSource(target));
        }

        public void PlayDogHappy(GameObject target)
        {
            PlayAudio("DuckHunter/Audios/DogHappy", GetAudioSource(target));
        }

        public void PlayGameStart()
        {
            PlayAudio("DuckHunter/Audios/GameStart", null);
        }

        public void PlayGameOver()
        {
            PlayAudio("DuckHunter/Audios/GameOver", null);
        }

        public void PlayGamePass()
        {
            PlayAudio("DuckHunter/Audios/GamePass", null);
        }

        public void PlayFullScore()
        {
            PlayAudio("DuckHunter/Audios/FullScore", null);
        }

        public void PlayBtn()
        {
            AudioMgr.ins.PlayBtn();
        }

        private void PlayAudio(string audioPath, AudioSource audioSource)
        {
            AudioMgr.ins.Play(audioPath, audioSource);
        }

        private AudioSource GetAudioSource(GameObject target)
        {
            if (target == null) return null;
            return AudioMgr.GetAudioSource(target);
        }
    }
}
