using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core.Devices;
namespace PepperDash.Essentials.Core
{
///
/// Represents a level control item in a list, which can be used to control volume or mute functionality.
///
public class LevelControlListItem : AudioControlListItemBase
{
///
/// A reference to the IBasicVolumeWithFeedback device for control.
///
[JsonIgnore]
public IBasicVolumeWithFeedback LevelControl
{
get
{
if (_levelControl == null)
_levelControl = DeviceManager.GetDeviceForKey(ParentDeviceKey) as IBasicVolumeWithFeedback;
return _levelControl;
}
}
IBasicVolumeWithFeedback _levelControl;
///
/// Gets the name from the device if it implements IKeyName or else returns the Name property
///
[JsonProperty("preferredName")]
public string PreferredName
{
get
{
if (!string.IsNullOrEmpty(Name)) return Name;
else
{
if (LevelControl is IKeyName namedLevelControl)
{
if (namedLevelControl == null)
return "---";
return namedLevelControl.Name;
}
else return "---";
}
}
}
///
/// The key of the device in the DeviceManager for control
///
[JsonProperty("deviceKey")]
public string DeviceKey
{
get
{
if (string.IsNullOrEmpty(ItemKey)) return ParentDeviceKey;
else
{
return DeviceManager.AllDevices.
Where(d => d.Key.Contains(ParentDeviceKey) && d.Key.Contains(ItemKey)).FirstOrDefault()?.Key ?? $"{ParentDeviceKey}--{ItemKey}";
}
}
}
///
/// Indicates if the item is a level, mute , or both
///
[JsonProperty("type")]
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public eLevelControlType Type { get; set; }
///
/// Indicates if the item is a mic or not.
///
[JsonProperty("isMic", NullValueHandling = NullValueHandling.Ignore)]
public bool? IsMic { get; set; }
///
/// Indicates if the item should show the raw level in the UI.
///
[JsonProperty("showRawLevel", NullValueHandling = NullValueHandling.Ignore)]
public bool? ShowRawLevel { get; set; }
}
///
/// Indicates the type of level control item.
///
[Flags]
public enum eLevelControlType
{
///
/// Indicates that the item is a level control only
///
Level = 1,
///
/// Indicates that the item is a mute control only
///
Mute = 2,
///
/// Indicates that the item is both a level and mute control
///
LevelAndMute = Level | Mute,
}
}