﻿using DarkTonic.MasterAudio;
using System.Collections.Generic;
using UnityEngine;

namespace ImpactCFX.MasterAudio
{
    public enum CollisionSoundGroupSelectionMode
    {
        [Tooltip("A sound group will be selected at random.")]
        Random,
        [Tooltip("A sound group will be selected based on the collision velocity, with the first element being the lowest velocity and the last element being the highest velocity.")]
        Velocity
    }

    [CreateAssetMenu(fileName = "New Impact Master Audio Effect", menuName = "Impact CFX/Master Audio Effect", order = 0)]
    public class ImpactMasterAudioEffectAuthoring : ImpactEffectAuthoringBase
    {
        [System.Serializable]
        public struct CollisionSoundGroup
        {
            [SoundGroup]
            public string SoundGroup;
        }

        [Tooltip("The velocity magnitude range to use when calculating collision intensity.")]
        [SerializeField]
        private Range velocityReferenceRange = new Range(1, 10);

        [Tooltip("Should volume be scaled based on the velocity?")]
        [SerializeField]
        private bool scaleVolumeWithVelocity = true;
        [Tooltip("How much the normal should affect the collision intensity.")]
        [SerializeField]
        private float collisionNormalInfluence = 1;

        [SerializeField]
        [Tooltip("Sound groups that will be used for collisions.")]
        private List<CollisionSoundGroup> collisionSoundGroups = new List<CollisionSoundGroup>();
        [SerializeField]
        [Tooltip("How a sound group will be selected from the sound groups list.")]
        private CollisionSoundGroupSelectionMode soundGroupSelectionMode;

        [SerializeField]
        [SoundGroup]
        [Tooltip("The sound group to use when sliding.")]
        private string slideSoundGroup;
        [SerializeField]
        [SoundGroup]
        [Tooltip("The sound group to use when rolling.")]
        private string rollSoundGroup;

        public IReadOnlyList<CollisionSoundGroup> CollisionSoundGroups => collisionSoundGroups.AsReadOnly();

        public string SlideSoundGroup => slideSoundGroup;
        public string RollSoundGroup => rollSoundGroup;

        public MasterAudioEffect GetMasterAudioEffect()
        {
            return new MasterAudioEffect()
            {
                EffectID = GetID(),
                VelocityReferenceRange = velocityReferenceRange,
                ScaleVolumeWithVelocity = scaleVolumeWithVelocity,
                CollisionNormalInfluence = collisionNormalInfluence,
                CollisionSoundGroupSelectionMode = soundGroupSelectionMode
            };
        }
    }
}
