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

namespace Domain.Entities.Members.Logs
{
    /// <summary>
    /// 사용자 이메일 변경 내역
    /// </summary>
    public class MemberEmailChangeLog
    {
        [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? BeforeEmail { get; private set; }

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

        public string? Referer { get; private set; }

        public string? IpAddress { get; private set; }

        public string? UserAgent { get; private set; }

        public DateTime CreatedAt { get; private set; }

        protected MemberEmailChangeLog() { }

        public MemberEmailChangeLog(
            int memberID,
            string? beforeEmail,
            string afterEmail,
            string? referer,
            string? ipAddress,
            string? userAgent
        ) {
            if (string.IsNullOrWhiteSpace(afterEmail))
            {
                throw new ArgumentException("AfterEmail is required.", nameof(afterEmail));
            }

            MemberID = memberID;
            BeforeEmail = beforeEmail;
            AfterEmail = afterEmail;
            Referer = referer;
            IpAddress = ipAddress;
            UserAgent = userAgent;
            CreatedAt = DateTime.UtcNow;
        }
    }
}