ChannelTitle.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System.ComponentModel.DataAnnotations;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. using Domain.Entities.Members;
  4. namespace Domain.Entities.Donations;
  5. /// <summary>
  6. /// 크리에이터가 직접 설정한 채널 전용 칭호 (투네이션 방식).
  7. /// 누적 후원 금액을 달성한 후원자에게 자동 부여됨.
  8. /// </summary>
  9. public sealed class ChannelTitle
  10. {
  11. [ForeignKey(nameof(ChannelID))]
  12. public Channel Channel { get; private set; } = null!;
  13. [Key]
  14. public int ID { get; private set; }
  15. public int ChannelID { get; private set; }
  16. public string Name { get; private set; } = default!;
  17. public string? Description { get; private set; }
  18. public long MinAmount { get; private set; }
  19. public string Color { get; private set; } = "#A855F7";
  20. public string? IconUrl { get; private set; }
  21. public int SortOrder { get; private set; }
  22. public bool IsActive { get; private set; } = true;
  23. public DateTime? UpdatedAt { get; private set; }
  24. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  25. private ChannelTitle() { }
  26. private ChannelTitle(int channelID, string name, long minAmount, string color)
  27. {
  28. if (channelID <= 0)
  29. {
  30. throw new ArgumentOutOfRangeException(nameof(channelID));
  31. }
  32. if (string.IsNullOrWhiteSpace(name))
  33. {
  34. throw new ArgumentException("Name is required.", nameof(name));
  35. }
  36. if (name.Length > 20)
  37. {
  38. throw new ArgumentOutOfRangeException(nameof(name));
  39. }
  40. if (minAmount < 0)
  41. {
  42. throw new ArgumentOutOfRangeException(nameof(minAmount));
  43. }
  44. ChannelID = channelID;
  45. Name = name;
  46. MinAmount = minAmount;
  47. Color = string.IsNullOrWhiteSpace(color) ? "#A855F7" : color;
  48. }
  49. public static ChannelTitle Create(int channelID, string name, long minAmount, string color)
  50. {
  51. return new(channelID, name, minAmount, color);
  52. }
  53. public void Update(string name, string? description, long minAmount, string color, string? iconUrl, bool isActive)
  54. {
  55. if (string.IsNullOrWhiteSpace(name))
  56. {
  57. throw new ArgumentException("Name is required.", nameof(name));
  58. }
  59. if (name.Length > 20)
  60. {
  61. throw new ArgumentOutOfRangeException(nameof(name));
  62. }
  63. if (description != null && description.Length > 100)
  64. {
  65. throw new ArgumentOutOfRangeException(nameof(description));
  66. }
  67. if (minAmount < 0)
  68. {
  69. throw new ArgumentOutOfRangeException(nameof(minAmount));
  70. }
  71. Name = name;
  72. Description = description;
  73. MinAmount = minAmount;
  74. Color = string.IsNullOrWhiteSpace(color) ? Color : color;
  75. IconUrl = iconUrl;
  76. IsActive = isActive;
  77. UpdatedAt = DateTime.UtcNow;
  78. }
  79. public void SetOrder(int order)
  80. {
  81. SortOrder = order;
  82. UpdatedAt = DateTime.UtcNow;
  83. }
  84. }