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

namespace bitforum.Models.Page
{
    [Table("Document")]
    [Index(nameof(Code), Name = "IX_Document_Code", IsUnique = true)]
    [Index(nameof(IsActive), Name = "IX_Document_IsActive")]
    public class Document
    {
        [Key]
        public int ID { get; set; }

        [Required]
        [DisplayName("주소")]
        [DataType(DataType.Text)]
        [MaxLength(30)]
        [RegularExpression(@"^[a-zA-Z0-9]+$", ErrorMessage = "Code는 영문 및 숫자로만 구성되어야 합니다.")]
        public string Code { get; set; }

        [Required]
        [DisplayName("제목")]
        [DataType(DataType.Text)]
        [MaxLength(120)]
        public string Subject { get; set; }

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

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

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

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

        [Display(Name = "등록일시")]
        [DataType(DataType.DateTime)]
        public DateTime? CreatedAt { get; set; } = null;
    }
}
