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

namespace Domain.Entities.Members.Logs
{
    /// <summary>
    /// 경험치 변동 내역
    /// </summary>
    public class MemberExpLog
    {
        [ForeignKey(nameof(MemberID))]
        public virtual Member Member { get; private set; } = null!;

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

        public int MemberID { get; private set; }

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

        public int Amount { get; private set; }

        public long Balance { get; private set; }

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

        private MemberExpLog() { }

        private MemberExpLog(int memberID, string reason, int amount, long balance)
        {
            if (memberID <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(memberID));
            }

            if (string.IsNullOrWhiteSpace(reason))
            {
                throw new ArgumentException("Reason is required.", nameof(reason));
            }

            if (reason.Length > 200)
            {
                throw new ArgumentOutOfRangeException(nameof(reason));
            }

            MemberID = memberID;
            Reason = reason;
            Amount = amount;
            Balance = balance;
            CreatedAt = DateTime.UtcNow;
        }

        public static MemberExpLog Create(int memberID, string reason, int amount, long balance)
        {
            return new(memberID, reason, amount, balance);
        }
    }
}