using Microsoft.EntityFrameworkCore;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace bitforum.Models.BBS
{
    [Table("Board")]
    [Index(nameof(Code), Name = "IX_Board_Code", IsUnique = true)]
    [Index(nameof(Name), Name = "IX_Board_Name")]
    [Index(nameof(Order), Name = "IX_Board_Order")]
    [Index(nameof(IsSearch), Name = "IX_Board_IsSearch")]
    [Index(nameof(IsActive), Name = "IX_Board_IsActive")]
    [Index(nameof(Posts), Name = "IX_Board_Posts")]
    [Index(nameof(Comments), Name = "IX_Board_Comments")]
    public class Board
    {
        [ForeignKey("BoardGroupID")]
        public BoardGroup BoardGroup { get; set; } = null!;

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

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

        [Required]
        [DisplayName("분류 ID")]
        [Comment("분류 ID")]
        public int BoardGroupID { get; set; }

        [Required]
        [DisplayName("게시판 주소")]
        [Comment("게시판 주소")]
        [DataType(DataType.Text)]
        [StringLength(70)]
        public string Code { get; set; } = null!;

        [Required]
        [DisplayName("게시판 이름")]
        [Comment("게시판 이름")]
        [DataType(DataType.Text)]
        [StringLength(70)]
        public string Name { get; set; } = null!;

        [Required]
        [DisplayName("순서")]
        [Comment("순서")]
        public short Order { get; set; } = 0;

        [Required]
        [DisplayName("검색 여부")]
        [Comment("검색 여부")]
        public bool IsSearch { get; set; } = false;

        [Required]
        [DisplayName("사용 여부")]
        [Comment("사용 여부")]
        public bool IsActive { get; set; } = false;

        [DisplayName("게시글 수")]
        [Comment("게시글 수")]
        public int Posts { get; set; } = 0;

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

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

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