using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.ApplicationCommandOption;
namespace Discord.Rest
{
///
/// Represents a Rest-based implementation of .
///
public class RestApplicationCommandOption : IApplicationCommandOption
{
#region RestApplicationCommandOption
///
public ApplicationCommandOptionType Type { get; private set; }
///
public string Name { get; private set; }
///
public string Description { get; private set; }
///
public bool? Default { get; private set; }
///
public bool? Required { get; private set; }
///
/// A collection of 's for this command.
///
public IReadOnlyCollection Choices { get; private set; }
///
/// A collection of 's for this command.
///
public IReadOnlyCollection Options { get; private set; }
internal RestApplicationCommandOption() { }
internal static RestApplicationCommandOption Create(Model model)
{
var options = new RestApplicationCommandOption();
options.Update(model);
return options;
}
internal void Update(Model model)
{
Type = model.Type;
Name = model.Name;
Description = model.Description;
if (model.Default.IsSpecified)
Default = model.Default.Value;
if (model.Required.IsSpecified)
Required = model.Required.Value;
Options = model.Options.IsSpecified
? model.Options.Value.Select(x => Create(x)).ToImmutableArray()
: null;
Choices = model.Choices.IsSpecified
? model.Choices.Value.Select(x => new RestApplicationCommandChoice(x)).ToImmutableArray()
: null;
}
#endregion
#region IApplicationCommandOption
IReadOnlyCollection IApplicationCommandOption.Options
=> Options;
IReadOnlyCollection IApplicationCommandOption.Choices
=> Choices;
#endregion
}
}