Channel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. namespace Domain.Entities.Members
  2. {
  3. public class Channel
  4. {
  5. public virtual Member Member { get; private set; } = null!;
  6. public int ID { get; private set; }
  7. public int MemberID { get; private set; }
  8. public string SID { get; private set; } = default!;
  9. public string Name { get; private set; } = default!;
  10. public string? Handle { get; private set; }
  11. public string YouTubeUrl { get; private set; } = default!;
  12. public decimal PlatformFeeRate { get; private set; } = 0;
  13. public bool IsVerified { get; private set; } = false;
  14. public bool IsActive { get; private set; } = false;
  15. public DateTime? UpdatedAt { get; private set; }
  16. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  17. private Channel() { }
  18. private Channel(int memberID, string sid, string name, string youtubeUrl)
  19. {
  20. if (memberID <= 0)
  21. {
  22. throw new ArgumentOutOfRangeException(nameof(memberID));
  23. }
  24. if (string.IsNullOrWhiteSpace(sid))
  25. {
  26. throw new ArgumentException("SID is required.", nameof(sid));
  27. }
  28. if (sid.Length != 24)
  29. {
  30. throw new ArgumentOutOfRangeException(nameof(sid));
  31. }
  32. if (string.IsNullOrWhiteSpace(name))
  33. {
  34. throw new ArgumentException("Name is required.", nameof(name));
  35. }
  36. if (name.Length > 200)
  37. {
  38. throw new ArgumentOutOfRangeException(nameof(name));
  39. }
  40. if (string.IsNullOrWhiteSpace(youtubeUrl))
  41. {
  42. throw new ArgumentException("YouTubeUrl is required.", nameof(youtubeUrl));
  43. }
  44. if (youtubeUrl.Length > 255)
  45. {
  46. throw new ArgumentOutOfRangeException(nameof(youtubeUrl));
  47. }
  48. MemberID = memberID;
  49. SID = sid;
  50. Name = name;
  51. YouTubeUrl = youtubeUrl;
  52. }
  53. public static Channel Create(int memberID, string sid, string name, string youtubeUrl)
  54. {
  55. return new(memberID, sid, name, youtubeUrl);
  56. }
  57. public void Update(string name, string? handle, string youtubeUrl, decimal platformFeeRate, bool isVerified, bool isActive)
  58. {
  59. if (string.IsNullOrWhiteSpace(name))
  60. {
  61. throw new ArgumentException("Name is required.", nameof(name));
  62. }
  63. if (name.Length > 200)
  64. {
  65. throw new ArgumentOutOfRangeException(nameof(name));
  66. }
  67. if (handle is not null && handle.Length > 30)
  68. {
  69. throw new ArgumentOutOfRangeException(nameof(handle));
  70. }
  71. if (string.IsNullOrWhiteSpace(youtubeUrl))
  72. {
  73. throw new ArgumentException("YouTubeUrl is required.", nameof(youtubeUrl));
  74. }
  75. if (youtubeUrl.Length > 255)
  76. {
  77. throw new ArgumentOutOfRangeException(nameof(youtubeUrl));
  78. }
  79. if (platformFeeRate < 0 || platformFeeRate > 100)
  80. {
  81. throw new ArgumentOutOfRangeException(nameof(platformFeeRate));
  82. }
  83. Name = name;
  84. Handle = handle;
  85. YouTubeUrl = youtubeUrl;
  86. PlatformFeeRate = platformFeeRate;
  87. IsVerified = isVerified;
  88. IsActive = isActive;
  89. UpdatedAt = DateTime.UtcNow;
  90. }
  91. }
  92. }