using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Domain.Entities.Donations.ValueObject;
using Domain.Entities.Members;

namespace Domain.Entities.Donations;

public class DonationRanking
{
    [ForeignKey(nameof(ChannelID))]
    public virtual Channel? Channel { get; private set; }

    [ForeignKey(nameof(SponsorMemberID))]
    public virtual Member? Sponsor { get; private set; }

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

    public int ChannelID { get; private set; }

    public int SponsorMemberID { get; private set; }

    public RankPeriodType PeriodType { get; private set; }

    public DateTime PeriodStart { get; private set; }

    public DateTime? PeriodEnd { get; private set; }

    public int Rank { get; private set; }

    public int TotalAmount { get; private set; }

    public int DonationCount { get; private set; }

    public string SponsorName { get; private set; } = default!;

    public bool IsActive { get; private set; } = true;

    public DateTime? UpdatedAt { get; private set; }

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

    private DonationRanking() { }

    public static DonationRanking Create(
        int channelID, 
        int sponsorMemberID, 
        RankPeriodType periodType,
        DateTime periodStart, 
        DateTime? periodEnd, 
        int totalAmount,
        int donationCount, 
        string sponsorName, 
        int rank
    ) {
        return new DonationRanking
        {
            ChannelID = channelID,
            SponsorMemberID = sponsorMemberID,
            PeriodType = periodType,
            PeriodStart = periodStart,
            PeriodEnd = periodEnd,
            TotalAmount = totalAmount,
            DonationCount = donationCount,
            SponsorName = sponsorName,
            Rank = rank
        };
    }

    public void UpdateRanking(int totalAmount, int donationCount, int rank, string sponsorName)
    {
        TotalAmount = totalAmount;
        DonationCount = donationCount;
        Rank = rank;
        SponsorName = sponsorName;
        UpdatedAt = DateTime.UtcNow;
    }
}