WalletTransaction.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Domain.Entities.Common.ValueObject;
  2. using Domain.Entities.Wallets.ValueObject;
  3. namespace Domain.Entities.Wallets
  4. {
  5. public class WalletTransaction
  6. {
  7. public virtual Wallet Wallet { get; private set; } = null!;
  8. public int ID { get; private set; }
  9. public Guid WalletKey { get; private set; }
  10. public WalletBalanceType BalanceType { get; private set; }
  11. public WalletTransactionType TxType { get; private set; }
  12. public Money Amount { get; private set; } = Money.KRW(0);
  13. public Money BalanceAfter { get; private set; } = Money.KRW(0);
  14. public string Reason { get; private set; } = default!;
  15. public string? RefID { get; private set; }
  16. public string? UserID { get; private set; }
  17. public string? Memo { get; private set; }
  18. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  19. private WalletTransaction() { }
  20. private WalletTransaction(
  21. Guid walletKey,
  22. WalletBalanceType balanceType,
  23. WalletTransactionType txType,
  24. Money amount,
  25. Money balanceAfter,
  26. string reason,
  27. string? refID,
  28. string? userID,
  29. string? memo
  30. ) {
  31. WalletKey = walletKey;
  32. BalanceType = balanceType;
  33. TxType = txType;
  34. Amount = amount;
  35. BalanceAfter = balanceAfter;
  36. Reason = reason;
  37. RefID = refID;
  38. UserID = userID;
  39. Memo = memo;
  40. }
  41. public static WalletTransaction Create(
  42. Guid walletKey,
  43. WalletBalanceType balanceType,
  44. WalletTransactionType txType,
  45. Money amount,
  46. Money balanceAfter,
  47. string reason,
  48. string? refID = null,
  49. string? userID = null,
  50. string? memo = null
  51. ) {
  52. if (walletKey == Guid.Empty)
  53. {
  54. throw new ArgumentException("WalletKey is required.", nameof(walletKey));
  55. }
  56. if (amount.IsZero || amount.Value <= 0)
  57. {
  58. throw new ArgumentException("Transaction amount must be positive.", nameof(amount));
  59. }
  60. if (string.IsNullOrWhiteSpace(reason))
  61. {
  62. throw new ArgumentException("Reason is required.", nameof(reason));
  63. }
  64. return new WalletTransaction(walletKey, balanceType, txType, amount, balanceAfter, reason, refID, userID, memo);
  65. }
  66. }
  67. }