using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using bitforum.Constants;
using bitforum.Models.Account;

namespace bitforum.Models.Log
{
    /// <summary>
    /// 이메일 발송 내역
    /// </summary>
    [Table("EmailLog")]
    [Index(nameof(MemberID), Name = "IX_EmailLog_MemberID")]
    [Index(nameof(Status), Name = "IX_EmailLog_Status")]
    public class EmailLog
    {
        public virtual Member Member { get; set; } = null!;

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DisplayName("PK")]
        [Comment("PK")]
        public int ID { get; set; }

        [ForeignKey("MemberID")]
        [DisplayName("회원 ID")]
        [Comment("회원 ID")]
        public int? MemberID { get; set; } = null;

        [DisplayName("처리 여부")]
        [Comment("처리 여부")]
        [Column(TypeName = "nvarchar(20)")]
        public MailStatus Status { get; set; } = MailStatus.Pending;

        [DisplayName("제목")]
        [Comment("제목")]
        [DataType(DataType.Text)]
        [StringLength(255)]
        public string Subject { get; set; } = null!;

        [DisplayName("내용")]
        [Comment("내용")]
        [DataType(DataType.Html)]
        public string? Message { get; set; } = null;

        [DisplayName("수신 주소")]
        [Comment("수신 주소")]
        [StringLength(120)]
        public string ToAddress { get; set; } = null!;

        [DisplayName("수신자")]
        [Comment("수신자")]
        [StringLength(60)]
        public string? ToName { get; set; } = null;

        [DisplayName("발신 주소")]
        [Comment("발신 주소")]
        [StringLength(120)]
        public string FromAddress { get; set; } = null!;

        [DisplayName("발신자")]
        [Comment("발신자")]
        [StringLength(60)]
        public string? FromName { get; set; }

        [DisplayName("처리 일시")]
        [Comment("처리 일시")]
        [DataType(DataType.DateTime)]
        public DateTime? ProcessedAt { get; set; } = null;

        [DisplayName("등록 일시")]
        [Comment("등록 일시")]
        [DataType(DataType.DateTime)]
        public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    }
}
