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

public class MusicManager: Singleton<MusicManager> {

    #region Source
    [SerializeField]
    private AudioSource source;
    public AudioSource Source {
        get {
            if(source == null) {
                source = GameObject.FindGameObjectWithTag("MM").GetComponent<AudioSource>();
            }
            return source;
        }
    }
    [Header("Sounds")]
    [Space(10)]
    #endregion

    #region Audio Clips
    [SerializeField]
    private AudioClip buttonClick;
    public AudioClip ButtonClick {
        get { return NullCheck(buttonClick); }
    }

    [SerializeField]
    private AudioClip dooDeeDoo;
    public AudioClip DooDeeDoo {
        get { return NullCheck(dooDeeDoo); }
    }

    [SerializeField]
    private AudioClip eleGunShot;
    public AudioClip EleGunShot {
        get { return NullCheck(eleGunShot); }
    }

    [SerializeField]
    private AudioClip lightGunShot;
    public AudioClip LightGunShot {
        get { return NullCheck(lightGunShot); }
    }

    [SerializeField]
    private AudioClip soundGunShot;
    public AudioClip SoundGunShot {
        get { return NullCheck(soundGunShot); }
    }

    [SerializeField]
    private AudioClip robotDie;
    public AudioClip RobotDie {
        get { return NullCheck(robotDie); }
    }

    [SerializeField]
    private AudioClip smallExplosion;
    public AudioClip SmallExplosion {
        get { return NullCheck(smallExplosion); }
    }

    [SerializeField]
    private AudioClip generatorOn;
    public AudioClip GeneratorOn {
        get { return NullCheck(generatorOn); }
    }

    [SerializeField]
    private AudioClip largeShatter;
    public AudioClip LargeShatter {
        get { return NullCheck(largeShatter); }
    }

    [SerializeField]
    private AudioClip splat;
    public AudioClip Splat {
        get { return NullCheck(splat); }
    }


    #endregion


    public AudioClip MapAudio(Sounds s) {
            MusicManager m = MusicManager.Instance;

        switch(s) {
            case Sounds.Button:
                return m.buttonClick;
            case Sounds.DooDeeDoo:
                return m.dooDeeDoo;
            case Sounds.ElectricityShot:
                return m.eleGunShot;
            case Sounds.LightShot:
                return m.LightGunShot;
            case Sounds.RobotDie:
                return m.robotDie;
            case Sounds.SmallExplosion:
                return m.smallExplosion;
            case Sounds.SoundGun:
                return m.soundGunShot;
            case Sounds.GeneratorOn:
                return m.generatorOn;
            case Sounds.LargeShatter:
                return m.largeShatter;
            case Sounds.Splat:
                return m.splat;
            default:
                return m.buttonClick;
        }
    }



    #region Source Functions
    public void PlayOneShot(AudioClip c) {
        Source.PlayOneShot(c);
    }

    public AudioClip NullCheck(AudioClip c) {
        if (c == null) {
            Debug.LogError(c.name);
        }
        return c;
    }

    public void ResetSource() {
        Source.volume = 1f;
        Source.pitch = 1f;
    }

    public void SetVolume(float volume) {
        Source.volume = volume;
    }

    public void SetVolume() {
        SetVolume(1f);
    }

    public void SetPitch(float pitch) {
        Source.pitch = pitch;
    }

    public void SetPitch() {
        SetPitch(1f);
    }
    #endregion

}
