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

namespace bitforum.Models.BBS
{
    [Table("Post")]
    [Index(nameof(Subject), Name = "IX_Post_Subject")]
    [Index(nameof(SID), Name = "IX_Post_SID")]
    [Index(nameof(Email), Name = "IX_Post_Email")]
    [Index(nameof(Name), Name = "IX_Post_Name")]
    [Index(nameof(IsReply), Name = "IX_Post_IsReply")]
    [Index(nameof(IsSecret), Name = "IX_Post_IsSecret")]
    [Index(nameof(IsNotice), Name = "IX_Post_IsNotice")]
    [Index(nameof(IsSpeaker), Name = "IX_Post_IsSpeaker")]
    [Index(nameof(IsDeleted), Name = "IX_Post_IsDeleted")]
    [Index(nameof(Views), Name = "IX_Post_Views")]
    [Index(nameof(Likes), Name = "IX_Post_Likes")]
    [Index(nameof(Dislikes), Name = "IX_Post_Dislikes")]
    [Index(nameof(Comments), Name = "IX_Post_Comments")]
    [Index(nameof(Blames), Name = "IX_Post_Blames")]
    [Index(nameof(Files), Name = "IX_Post_Files")]
    [Index(nameof(Images), Name = "IX_Post_Images")]
    [Index(nameof(Videos), Name = "IX_Post_Videos")]
    [Index(nameof(Tags), Name = "IX_Post_Tags")]
    [Index(nameof(LastReplyUpdatedAt), Name = "IX_Post_LastReplyUpdatedAt")]
    [Index(nameof(LastCommentUpdatedAt), Name = "IX_Post_LastCommentUpdatedAt")]
    [Index(nameof(CreatedAt), Name = "IX_Post_CreatedAt")]
    public class Post
    {
        [ForeignKey("BoardID")]
        public virtual Board Board { get; set; } = null!;

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

        public virtual List<Comment> Comment { get; set; } = new List<Comment>();

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

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

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

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

        [Required]
        [DisplayName("내용")]
        [Comment("내용")]
        [DataType(DataType.Html)]
        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 IsReply { get; set; } = false;

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

        [DisplayName("일반 공지 여부")]
        [Comment("일반 공지 여부")]
        public bool IsNotice { get; set; } = false;

        [DisplayName("전체 공지 여부")]
        [Comment("전체 공지 여부")]
        public bool IsSpeaker { get; set; } = false;

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

        [DisplayName("조회 수")]
        [Comment("조회 수")]
        public uint Views { get; set; } = 0;

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

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

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

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

        [DisplayName("파일 수")]
        [Comment("파일 수")]
        public sbyte Files { get; set; } = 0;

        [DisplayName("이미지 수")]
        [Comment("이미지 수")]
        public sbyte Images { get; set; } = 0;

        [DisplayName("동영상 수")]
        [Comment("동영상 수")]
        public sbyte Videos { get; set; } = 0;

        [DisplayName("Tag 수")]
        [Comment("Tag 수")]
        public sbyte Tags { 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? LastReplyUpdatedAt { get; set; } = null;

        [DisplayName("마지막 댓글 일시")]
        [Comment("마지막 댓글 일시")]
        [DataType(DataType.DateTime)]
        public DateTime? LastCommentUpdatedAt { 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; }
    }
}
