Channel.cs 3.7 KB

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