using Domain.Entities.Forum.Boards;
using Domain.Entities.Forum.Posts;
using Domain.Entities.Members;
using Domain.Entities.Forum.ValueObject;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Domain.Entities.Forum.Comments
{
    [Table("CommentReaction")]
    [Index(nameof(BoardID))]
    [Index(nameof(PostID))]
    [Index(nameof(CommentID))]
    [Index(nameof(MemberID))]
    [Index(nameof(Reaction))]
    [Index(nameof(CreatedAt))]
    [Index(nameof(CommentID), nameof(ID))]
    [Index(nameof(CommentID), nameof(MemberID), IsUnique = true)]
    public class CommentReaction
    {
        [ForeignKey(nameof(BoardID))]
        public virtual Board Board { get; set; } = null!;

        [ForeignKey(nameof(PostID))]
        public virtual Post Post { get; set; } = null!;

        [ForeignKey(nameof(CommentID))]
        public virtual Comment Comment { get; set; } = null!;

        [ForeignKey(nameof(MemberID))]
        public virtual Member Member { get; set; } = null!;

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

        [Comment("게시판 ID")]
        public int BoardID { get; set; }

        [Comment("게시글 ID")]
        public int PostID { get; set; }

        [Comment("댓글 ID")]
        public int CommentID { get; set; }

        [Comment("회원 ID")]
        public int MemberID { get; set; }

        [Comment("반응 구분")]
        [EnumDataType(typeof(Reaction), ErrorMessage = "{0}는 {1} 중 하나를 선택하세요.")]
        public Reaction Reaction { get; set; }

        [Comment("IP Address")]
        [MaxLength(50)]
        public string? IpAddress { get; set; }

        [Comment("User-agent")]
        [MaxLength(255)]
        public string? UserAgent { get; set; }

        [Comment("수정 일시")]
        public DateTime? UpdatedAt { get; set; }

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