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

namespace Domain.Entities.Forum.Logs
{
    [Table("PostUpdateLog")]
    [Index(nameof(PostID))]
    [Index(nameof(MemberID))]
    [Index(nameof(SubjectDiff))]
    [Index(nameof(ContentDiff))]
    [Index(nameof(PostID), nameof(ID))]
    [Index(nameof(PostID), nameof(MemberID))]
    [Index(nameof(PostID), nameof(MemberID), nameof(ID))]
    public class PostUpdateLog
    {
        [ForeignKey(nameof(PostID))]
        public Post Post { get; set; } = null!;

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

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

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

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

        [DisplayName("변경 제목")]
        [Comment("변경 제목")]
        [DataType(DataType.Text)]
        [StringLength(4000, ErrorMessage = "{0}은 {1}자 이하로 입력하세요.")]
        public string? SubjectDiff { get; set; }

        [DisplayName("변경 내용")]
        [Comment("변경 내용")]
        [DataType(DataType.Html)]
        [StringLength(4000, ErrorMessage = "{0}은 {1}자 이하로 입력하세요.")]
        public string? ContentDiff { get; set; }

        [DisplayName("비고")]
        [Comment("비고")]
        [StringLength(200, ErrorMessage = "{0}은 {1}자 이하로 입력하세요.")]
        public string? Note { get; set; }

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

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

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