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

namespace Domain.Entities.Members;

/// <summary>
/// 출석 기록
/// </summary>
public sealed class Attendance
{
    [ForeignKey(nameof(MemberID))]
    public Member Member { get; private set; } = null!;

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

    public int MemberID { get; private set; }

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

    public int ConsecutiveDays { get; private set; }

    public int ExpRewarded { get; private set; }

    public int PointRewarded { get; private set; }

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

    private Attendance() { }

    private Attendance(int memberID, string greeting, int consecutiveDays, int expRewarded, int pointRewarded)
    {
        if (memberID <= 0)
        {
            throw new ArgumentOutOfRangeException(nameof(memberID));
        }

        if (greeting != null && greeting.Length > 200)
        {
            throw new ArgumentOutOfRangeException(nameof(greeting));
        }

        MemberID = memberID;
        Greeting = greeting ?? "";
        ConsecutiveDays = consecutiveDays;
        ExpRewarded = expRewarded;
        PointRewarded = pointRewarded;
        CreatedAt = DateTime.UtcNow;
    }

    public static Attendance Create(int memberID, string greeting, int consecutiveDays, int expRewarded, int pointRewarded)
    {
        return new(memberID, greeting, consecutiveDays, expRewarded, pointRewarded);
    }

    public void AddRankBonus(int bonusExp, int bonusPoint)
    {
        ExpRewarded += bonusExp;
        PointRewarded += bonusPoint;
    }
}