|
| 1 | +using System; |
| 2 | +using System.Runtime.Serialization; |
| 3 | +using Core; |
| 4 | +using YamlDotNet.Serialization; |
| 5 | + |
| 6 | +namespace GitlabLabelSetUpper |
| 7 | +{ |
| 8 | + public class Label : ILabel |
| 9 | + { |
| 10 | + private static class Key |
| 11 | + { |
| 12 | + public const string Id = "id"; |
| 13 | + public const string Name = "name"; |
| 14 | + public const string Color = "color"; |
| 15 | + public const string Description = "description"; |
| 16 | + public const string Priority = "priority"; |
| 17 | + public const string Aliases = "aliases"; |
| 18 | + } |
| 19 | + |
| 20 | + [DataMember(Name = Key.Id, IsRequired = false)] |
| 21 | + [YamlMember(Alias = Key.Id, ApplyNamingConventions = false)] |
| 22 | + public int? Id { get; set; } |
| 23 | + |
| 24 | + [DataMember(Name = Key.Name, IsRequired = true)] |
| 25 | + [YamlMember(Alias = Key.Name, ApplyNamingConventions = false)] |
| 26 | + public string? Name { get; set; } |
| 27 | + |
| 28 | + [DataMember(Name = Key.Color, IsRequired = true)] |
| 29 | + [YamlMember(Alias = Key.Color, ApplyNamingConventions = false)] |
| 30 | + public string? Color { get; set; } |
| 31 | + |
| 32 | + [DataMember(Name = Key.Description, IsRequired = false)] |
| 33 | + [YamlMember(Alias = Key.Description, ApplyNamingConventions = false)] |
| 34 | + public string? Description { get; set; } |
| 35 | + |
| 36 | + [DataMember(Name = Key.Priority, IsRequired = false)] |
| 37 | + [YamlMember(Alias = Key.Priority, ApplyNamingConventions = false)] |
| 38 | + public int? Priority { get; set; } |
| 39 | + |
| 40 | + [DataMember(Name = Key.Aliases, IsRequired = false)] |
| 41 | + [YamlMember(Alias = Key.Aliases, ApplyNamingConventions = false)] |
| 42 | + public string[]? Aliases { get; set; } |
| 43 | + |
| 44 | + public void ValidateOrThrow() |
| 45 | + { |
| 46 | + if (Name is null) |
| 47 | + { |
| 48 | + throw new ArgumentNullException(nameof(Name)); |
| 49 | + } |
| 50 | + if (Color is null) |
| 51 | + { |
| 52 | + throw new ArgumentNullException(nameof(Color)); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + public override string ToString() |
| 57 | + { |
| 58 | + if (Aliases is null) |
| 59 | + { |
| 60 | + return $"Id: {Id}, Name: {Name}, Color: {Color}, Description: {Description}, Priority: {Priority}"; |
| 61 | + } |
| 62 | + else |
| 63 | + { |
| 64 | + return $"Id: {Id}, Name: {Name}, Color: {Color}, Description: {Description}, Priority: {Priority}, Aliases: {string.Join(',', Aliases)}"; |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments