2020-01-03 12:49:24 +00:00
using System.Collections.Generic ;
2018-09-05 02:41:22 +00:00
using FluentValidation ;
2013-07-25 07:24:09 +00:00
using NzbDrone.Core.Annotations ;
2013-09-21 06:39:26 +00:00
using NzbDrone.Core.ThingiProvider ;
2015-03-17 04:33:34 +00:00
using NzbDrone.Core.Validation ;
2013-07-25 07:24:09 +00:00
namespace NzbDrone.Core.Notifications.Pushover
{
2013-10-12 18:44:40 +00:00
public class PushoverSettingsValidator : AbstractValidator < PushoverSettings >
{
public PushoverSettingsValidator ( )
{
RuleFor ( c = > c . UserKey ) . NotEmpty ( ) ;
2016-02-11 07:43:40 +00:00
RuleFor ( c = > c . Retry ) . GreaterThanOrEqualTo ( 30 ) . LessThanOrEqualTo ( 86400 ) . When ( c = > ( PushoverPriority ) c . Priority = = PushoverPriority . Emergency ) ;
RuleFor ( c = > c . Retry ) . GreaterThanOrEqualTo ( 0 ) . LessThanOrEqualTo ( 86400 ) . When ( c = > ( PushoverPriority ) c . Priority = = PushoverPriority . Emergency ) ;
2013-10-12 18:44:40 +00:00
}
}
2013-09-21 06:39:26 +00:00
public class PushoverSettings : IProviderConfig
2013-07-25 07:24:09 +00:00
{
2013-10-12 18:44:40 +00:00
private static readonly PushoverSettingsValidator Validator = new PushoverSettingsValidator ( ) ;
2014-08-05 20:51:06 +00:00
public PushoverSettings ( )
{
Priority = 0 ;
2018-09-05 02:41:22 +00:00
Devices = new string [ ] { } ;
2014-08-05 20:51:06 +00:00
}
2022-11-22 01:51:00 +00:00
// TODO: Get Pushover to change our app name (or create a new app) when we have a new logo
2020-09-22 20:31:58 +00:00
[FieldDefinition(0, Label = "API Key", Privacy = PrivacyLevel.ApiKey, HelpLink = "https://pushover.net/apps/clone/lidarr")]
2015-10-03 17:45:26 +00:00
public string ApiKey { get ; set ; }
2013-12-31 04:48:14 +00:00
2020-09-22 20:31:58 +00:00
[FieldDefinition(1, Label = "User Key", Privacy = PrivacyLevel.UserName, HelpLink = "https://pushover.net/")]
2015-10-03 17:45:26 +00:00
public string UserKey { get ; set ; }
2013-07-25 07:24:09 +00:00
2018-09-05 02:41:22 +00:00
[FieldDefinition(2, Label = "Devices", HelpText = "List of device names (leave blank to send to all devices)", Type = FieldType.Tag)]
public IEnumerable < string > Devices { get ; set ; }
[FieldDefinition(3, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(PushoverPriority))]
2015-10-03 17:45:26 +00:00
public int Priority { get ; set ; }
2013-07-25 07:24:09 +00:00
2018-09-05 02:41:22 +00:00
[FieldDefinition(4, Label = "Retry", Type = FieldType.Textbox, HelpText = "Interval to retry Emergency alerts, minimum 30 seconds")]
2016-02-11 07:43:40 +00:00
public int Retry { get ; set ; }
2018-09-05 02:41:22 +00:00
[FieldDefinition(5, Label = "Expire", Type = FieldType.Textbox, HelpText = "Maximum time to retry Emergency alerts, maximum 86400 seconds")]
2016-02-11 07:43:40 +00:00
public int Expire { get ; set ; }
2018-09-05 02:41:22 +00:00
[FieldDefinition(6, Label = "Sound", Type = FieldType.Textbox, HelpText = "Notification sound, leave blank to use the default", HelpLink = "https://pushover.net/api#sounds")]
2015-10-03 17:45:26 +00:00
public string Sound { get ; set ; }
2014-04-03 14:05:38 +00:00
2016-12-09 06:54:15 +00:00
public bool IsValid = > ! string . IsNullOrWhiteSpace ( UserKey ) & & Priority > = - 1 & & Priority < = 2 ;
2013-09-21 07:09:26 +00:00
2015-03-17 04:33:34 +00:00
public NzbDroneValidationResult Validate ( )
2013-09-21 07:09:26 +00:00
{
2015-03-17 04:33:34 +00:00
return new NzbDroneValidationResult ( Validator . Validate ( this ) ) ;
2013-09-21 07:09:26 +00:00
}
2013-07-25 07:24:09 +00:00
}
}