using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Domain.Entities.Donations;

public class CrewDonationSummary
{
    [ForeignKey(nameof(CrewSessionID))]
    public virtual CrewSession? CrewSession { get; private set; }

    [ForeignKey(nameof(CrewMemberID))]
    public virtual CrewMember? CrewMember { get; private set; }

    [Key]
    public int ID { get; private set; }

    public int CrewSessionID { get; private set; }

    public int CrewMemberID { get; private set; }

    public int TotalAmount { get; private set; }

    public int DonationCount { get; private set; }

    public decimal ContributionRate { get; private set; }

    public int Rank { get; private set; }

    public DateTime? UpdatedAt { get; private set; }

    public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;

    private CrewDonationSummary() { }

    public static CrewDonationSummary Create(int crewSessionID, int crewMemberID)
    {
        return new CrewDonationSummary
        {
            CrewSessionID = crewSessionID,
            CrewMemberID = crewMemberID
        };
    }

    public void AddDonation(int amount)
    {
        TotalAmount += amount;
        DonationCount++;
        UpdatedAt = DateTime.UtcNow;
    }

    public void UpdateContribution(decimal contributionRate, int rank)
    {
        ContributionRate = contributionRate;
        Rank = rank;
        UpdatedAt = DateTime.UtcNow;
    }
}