using System.ComponentModel.DataAnnotations.Schema; using Domain.Entities.Members; namespace Domain.Entities.Donations; /// /// 후원자별 × 채널별 누적 후원 금액 (칭호 획득 판정용). /// 복합 PK: (DonorMemberID, ChannelID) /// public sealed class DonorChannelStats { [ForeignKey(nameof(DonorMemberID))] public Member Donor { get; private set; } = null!; [ForeignKey(nameof(ChannelID))] public Channel Channel { get; private set; } = null!; public int DonorMemberID { get; private set; } public int ChannelID { get; private set; } public long CumulativeAmount { get; private set; } public int DonationCount { get; private set; } public DateTime? FirstDonatedAt { get; private set; } public DateTime? LastDonatedAt { get; private set; } public DateTime? UpdatedAt { get; private set; } public DateTime CreatedAt { get; private set; } = DateTime.UtcNow; private DonorChannelStats() { } private DonorChannelStats(int donorMemberID, int channelID) { if (donorMemberID <= 0) { throw new ArgumentOutOfRangeException(nameof(donorMemberID)); } if (channelID <= 0) { throw new ArgumentOutOfRangeException(nameof(channelID)); } DonorMemberID = donorMemberID; ChannelID = channelID; } public static DonorChannelStats Create(int donorMemberID, int channelID) { return new(donorMemberID, channelID); } public void AddDonation(long amount, DateTime when) { if (amount <= 0) { return; } CumulativeAmount += amount; DonationCount++; FirstDonatedAt ??= when; LastDonatedAt = when; UpdatedAt = DateTime.UtcNow; } }