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

namespace bitforum.Models.BBS
{
    [Table("Comment")]
    [Index(nameof(ParentID), Name = "IX_Comment_ParentID")]
    [Index(nameof(SID), Name = "IX_Comment_SID")]
    [Index(nameof(Email), Name = "IX_Comment_Email")]
    [Index(nameof(Name), Name = "IX_Comment_Name")]
    [Index(nameof(IsSecret), Name = "IX_Comment_IsSecret")]
    [Index(nameof(IsDeleted), Name = "IX_Comment_IsDeleted")]
    [Index(nameof(Likes), Name = "IX_Comment_Likes")]
    [Index(nameof(Dislikes), Name = "IX_Comment_Dislikes")]
    [Index(nameof(Blames), Name = "IX_Comment_Blames")]
    [Index(nameof(Replies), Name = "IX_Comment_Replies")]
    [Index(nameof(CreatedAt), Name = "IX_Comment_CreatedAt")]
    public class Comment
    {
        [ForeignKey("BoardID")]
        public Board Board { get; set; } = null!;

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

        [ForeignKey("MemberID")]
        public Member? Member { get; set; }

        public Comment? Parent { get; set; } = null;
        public ICollection<Comment> Reply { get; set; } = new List<Comment>();

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

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

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

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

        [DisplayName("부모 댓글 ID")]
        [Comment("부모 댓글 ID")]
        public int? ParentID { get; set; } = null;

        [Required]
        [DisplayName("댓글 깊이")]
        [Comment("댓글 깊이")]
        public ushort Depth { get; set; } = 0;

        [Required]
        [DisplayName("댓글 내용")]
        [Comment("댓글 내용")]
        [StringLength(4000)]
        public string Content { get; set; } = null!;

        [DisplayName("회원 SID")]
        [Comment("회원 SID")]
        [StringLength(20)]
        public string? SID { get; set; } = null;

        [DisplayName("회원 이메일")]
        [Comment("회원 이메일")]
        [StringLength(60)]
        public string? Email { get; set; } = null;

        [DisplayName("회원 이름")]
        [Comment("회원 이름")]
        [StringLength(20)]
        public string? Name { get; set; } = null;

        [DisplayName("댓글 비밀번호")]
        [Comment("댓글 비밀번호")]
        [StringLength(255)]
        public string? Password { get; set; } = null;

        [DisplayName("비밀글 여부")]
        [Comment("비밀글 여부")]
        public bool IsSecret { get; set; } = false;

        [DisplayName("삭제 여부")]
        [Comment("삭제 여부")]
        public bool IsDeleted { get; set; } = false;

        [DisplayName("좋아요")]
        [Comment("좋아요")]
        public uint Likes { get; set; } = 0;

        [DisplayName("싫어요")]
        [Comment("싫어요")]
        public uint Dislikes { get; set; } = 0;

        [DisplayName("신고 수")]
        [Comment("신고 수")]
        public uint Blames { get; set; } = 0;

        [DisplayName("대댓글 수")]
        [Comment("대댓글 수")]
        public uint Replies { get; set; } = 0;

        [DisplayName("IP")]
        [Comment("IP")]
        [StringLength(50)]
        public string IpAddress { get; set; } = null!;

        [DisplayName("User-Agent")]
        [Comment("User-Agent")]
        [StringLength(255)]
        public string UserAgent { get; set; } = null!;

        [DisplayName("삭제 일시")]
        [Comment("삭제 일시")]
        [DataType(DataType.DateTime)]
        public DateTime? DeletedAt { get; set; } = null;

        [DisplayName("수정 일시")]
        [Comment("수정 일시")]
        [DataType(DataType.DateTime)]
        public DateTime? UpdatedAt { get; set; } = null;

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