ChatRoomConfig.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.ComponentModel.DataAnnotations;
  2. namespace Domain.Entities.Chat;
  3. /// <summary>
  4. /// 채팅방 설정 (개미투자 D2) — RoomKey: main | stock:{code}.
  5. /// main 은 row 없이도 기본 오픈, 종목방은 row 존재 + IsActive 일 때만 오픈(상위 N 종목 단계 오픈 — d0 §5-④).
  6. /// </summary>
  7. public class ChatRoomConfig
  8. {
  9. /// <summary>룸 키 (PK) — main, stock:005930 형식</summary>
  10. [Key]
  11. public string RoomKey { get; private set; } = default!;
  12. /// <summary>활성 여부 — 종목방 단계 오픈 게이트</summary>
  13. public bool IsActive { get; private set; } = true;
  14. /// <summary>슬로우 모드 (초) — 0 이면 전역 rate limit 만 적용</summary>
  15. public short SlowModeSeconds { get; private set; }
  16. /// <summary>상단 고정 공지 (선택)</summary>
  17. public string? Notice { get; private set; }
  18. public DateTime UpdatedAt { get; private set; } = DateTime.UtcNow;
  19. private ChatRoomConfig() { }
  20. public static ChatRoomConfig Create(string roomKey, bool isActive = true, short slowModeSeconds = 0, string? notice = null)
  21. {
  22. if (string.IsNullOrWhiteSpace(roomKey) || roomKey.Length > 20)
  23. {
  24. throw new ArgumentException("roomKey must be 1~20 chars", nameof(roomKey));
  25. }
  26. if (slowModeSeconds < 0)
  27. {
  28. throw new ArgumentOutOfRangeException(nameof(slowModeSeconds));
  29. }
  30. return new ChatRoomConfig
  31. {
  32. RoomKey = roomKey.Trim(),
  33. IsActive = isActive,
  34. SlowModeSeconds = slowModeSeconds,
  35. Notice = string.IsNullOrWhiteSpace(notice) ? null : notice.Trim()
  36. };
  37. }
  38. public void Update(bool isActive, short slowModeSeconds, string? notice)
  39. {
  40. if (slowModeSeconds < 0)
  41. {
  42. throw new ArgumentOutOfRangeException(nameof(slowModeSeconds));
  43. }
  44. IsActive = isActive;
  45. SlowModeSeconds = slowModeSeconds;
  46. Notice = string.IsNullOrWhiteSpace(notice) ? null : notice.Trim();
  47. UpdatedAt = DateTime.UtcNow;
  48. }
  49. }