using Domain.Entities.Forum.Boards;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure.Persistence.Configurations.Forum.Boards;

public sealed class BoardMetaConfiguration : IEntityTypeConfiguration<BoardMeta>
{
    public void Configure(EntityTypeBuilder<BoardMeta> builder)
    {
        builder.HasIndex(x => x.BoardID).IsUnique();

        builder.OwnsOne(x => x.List, list =>
        {
            list.Property(x => x.HeaderContent).HasColumnName("List_HeaderContent");
            list.Property(x => x.ShowHeader).HasColumnName("List_ShowHeader");
            list.Property(x => x.FooterContent).HasColumnName("List_FooterContent");
            list.Property(x => x.ShowFooter).HasColumnName("List_ShowFooter");
            list.Property(x => x.Layout).HasColumnName("List_Layout").HasConversion<byte?>();
            list.Property(x => x.Sort).HasColumnName("List_Sort").HasConversion<byte?>();
            list.Property(x => x.PerPage).HasColumnName("List_PerPage");
            list.Property(x => x.AlwaysShowWriteButton).HasColumnName("List_AlwaysShowWriteButton");
            list.Property(x => x.ShowFooterListView).HasColumnName("List_ShowFooterListView");
            list.Property(x => x.IsNewIcon).HasColumnName("List_IsNewIcon");
            list.Property(x => x.IsHotIcon).HasColumnName("List_IsHotIcon");
            list.Property(x => x.ExceptNotice).HasColumnName("List_ExceptNotice");
            list.Property(x => x.ExceptSpeaker).HasColumnName("List_ExceptSpeaker");
        });

        builder.OwnsOne(x => x.View, view =>
        {
            view.Property(x => x.AllowBookmark).HasColumnName("View_AllowBookmark");
            view.Property(x => x.AllowLike).HasColumnName("View_AllowLike");
            view.Property(x => x.AllowDislike).HasColumnName("View_AllowDislike");
            view.Property(x => x.AllowPrint).HasColumnName("View_AllowPrint");
            view.Property(x => x.AllowSnsShare).HasColumnName("View_AllowSnsShare");
            view.Property(x => x.AllowPrevNextBotton).HasColumnName("View_AllowPrevNextBotton");
            view.Property(x => x.AllowBlame).HasColumnName("View_AllowBlame");
            view.Property(x => x.BlameHideCount).HasColumnName("View_BlameHideCount");
            view.Property(x => x.AllowContentLinkTargetBlank).HasColumnName("View_AllowContentLinkTargetBlank");
            view.Property(x => x.AllowPostUrlCopy).HasColumnName("View_AllowPostUrlCopy");
            view.Property(x => x.AllowPostUrlQrCode).HasColumnName("View_AllowPostUrlQrCode");
            view.Property(x => x.ShowMemberThumb).HasColumnName("View_ShowMemberThumb");
            view.Property(x => x.ShowMemberIcon).HasColumnName("View_ShowMemberIcon");
            view.Property(x => x.ShowMemberRegDate).HasColumnName("View_ShowMemberRegDate");
            view.Property(x => x.ShowMemberSummary).HasColumnName("View_ShowMemberSummary");
        });

        builder.OwnsOne(x => x.Write, write =>
        {
            write.Property(x => x.HeaderContent).HasColumnName("Write_HeaderContent");
            write.Property(x => x.ShowHeader).HasColumnName("Write_ShowHeader");
            write.Property(x => x.FooterContent).HasColumnName("Write_FooterContent");
            write.Property(x => x.ShowFooter).HasColumnName("Write_ShowFooter");
            write.Property(x => x.DefaultSubject).HasColumnName("Write_DefaultSubject");
            write.Property(x => x.DefaultContent).HasColumnName("Write_DefaultContent");
            write.Property(x => x.AllowEditor).HasColumnName("Write_AllowEditor");
            write.Property(x => x.AllowPrefix).HasColumnName("Write_AllowPrefix");
            write.Property(x => x.RequiredPrefix).HasColumnName("Write_RequiredPrefix");
            write.Property(x => x.AllowSecret).HasColumnName("Write_AllowSecret");
            write.Property(x => x.AllowTag).HasColumnName("Write_AllowTag");
            write.Property(x => x.TagLimit).HasColumnName("Write_TagLimit");
            write.Property(x => x.AllowImage).HasColumnName("Write_AllowImage");
            write.Property(x => x.ImageUploadLimit).HasColumnName("Write_ImageUploadLimit");
            write.Property(x => x.ImageUploadMaxSize).HasColumnName("Write_ImageUploadMaxSize");
            write.Property(x => x.AllowMedia).HasColumnName("Write_AllowMedia");
            write.Property(x => x.MediaUploadLimit).HasColumnName("Write_MediaUploadLimit");
            write.Property(x => x.AllowFile).HasColumnName("Write_AllowFile");
            write.Property(x => x.FileUploadLimit).HasColumnName("Write_FileUploadLimit");
            write.Property(x => x.FileUploadMaxSize).HasColumnName("Write_FileUploadMaxSize");
            write.Property(x => x.FileUploadExtension).HasColumnName("Write_FileUploadExtension");
        });

        builder.OwnsOne(x => x.Comment, comment =>
        {
            comment.Property(x => x.EnableComment).HasColumnName("Comment_EnableComment");
            comment.Property(x => x.PerPage).HasColumnName("Comment_PerPage");
            comment.Property(x => x.AllowLike).HasColumnName("Comment_AllowLike");
            comment.Property(x => x.AllowDisLike).HasColumnName("Comment_AllowDisLike");
            comment.Property(x => x.ShowMemberThumb).HasColumnName("Comment_ShowMemberThumb");
            comment.Property(x => x.ShowMemberIcon).HasColumnName("Comment_ShowMemberIcon");
            comment.Property(x => x.ContentPlaceholder).HasColumnName("Comment_ContentPlaceholder");
            comment.Property(x => x.MinContentLength).HasColumnName("Comment_MinContentLength");
            comment.Property(x => x.MaxContentLength).HasColumnName("Comment_MaxContentLength");
            comment.Property(x => x.EnableEditor).HasColumnName("Comment_EnableEditor");
            comment.Property(x => x.AllowSecret).HasColumnName("Comment_AllowSecret");
            comment.Property(x => x.BlameHideCount).HasColumnName("Comment_BlameHideCount");
            comment.Property(x => x.DeleteProtectionDays).HasColumnName("Comment_DeleteProtectionDays");
            comment.Property(x => x.UpdateProtectionDays).HasColumnName("Comment_UpdateProtectionDays");
            comment.Property(x => x.AllowDeleteProtection).HasColumnName("Comment_AllowDeleteProtection");
            comment.Property(x => x.AllowUpdateProtection).HasColumnName("Comment_AllowUpdateProtection");
            comment.Property(x => x.EnableCommentUpdateLog).HasColumnName("Comment_EnableCommentUpdateLog");
        });

        builder.OwnsOne(x => x.General, general =>
        {
            general.Property(x => x.DeleteProtectionDays).HasColumnName("General_DeleteProtectionDays");
            general.Property(x => x.UpdateProtectionDays).HasColumnName("General_UpdateProtectionDays");
            general.Property(x => x.AllowDeleteProtection).HasColumnName("General_AllowDeleteProtection");
            general.Property(x => x.AllowUpdateProtection).HasColumnName("General_AllowUpdateProtection");
            general.Property(x => x.EnableFileDownLog).HasColumnName("General_EnableFileDownLog");
            general.Property(x => x.EnableLinkClickLog).HasColumnName("General_EnableLinkClickLog");
            general.Property(x => x.EnablePostUpdateLog).HasColumnName("General_EnablePostUpdateLog");
        });

        builder.OwnsOne(x => x.Permission, permission =>
        {
            permission.Property(x => x.BoardAccess).HasColumnName("Permission_BoardAccess");
            permission.Property(x => x.PostView).HasColumnName("Permission_PostView");
            permission.Property(x => x.PostWrite).HasColumnName("Permission_PostWrite");
            permission.Property(x => x.CommentView).HasColumnName("Permission_CommentView");
            permission.Property(x => x.CommentWrite).HasColumnName("Permission_CommentWrite");
            permission.Property(x => x.ReplyWrite).HasColumnName("Permission_ReplyWrite");
            permission.Property(x => x.FileUpload).HasColumnName("Permission_FileUpload");
            permission.Property(x => x.FileDownload).HasColumnName("Permission_FileDownload");
        });

        builder.OwnsOne(x => x.Notify, notify =>
        {
            notify.Property(x => x.PostWriteNotify).HasColumnName("Notify_PostWriteNotify");
            notify.Property(x => x.CommentWriteNotify).HasColumnName("Notify_CommentWriteNotify");
            notify.Property(x => x.ReplyWriteNotify).HasColumnName("Notify_ReplyWriteNotify");
            notify.Ignore(x => x.PostWriteNotifyEnum);
            notify.Ignore(x => x.CommentWriteNotifyEnum);
            notify.Ignore(x => x.ReplyWriteNotifyEnum);
        });

        builder.OwnsOne(x => x.NotifyTemplate, template =>
        {
            template.Property(x => x.PostWriteEmailNotifySubject).HasColumnName("NotifyTemplate_PostWriteEmailNotifySubject");
            template.Property(x => x.PostWriteEmailNotifyContent).HasColumnName("NotifyTemplate_PostWriteEmailNotifyContent");
            template.Property(x => x.CommentWriteEmailNotifySubject).HasColumnName("NotifyTemplate_CommentWriteEmailNotifySubject");
            template.Property(x => x.CommentWriteEmailNotifyContent).HasColumnName("NotifyTemplate_CommentWriteEmailNotifyContent");
            template.Property(x => x.ReplyWriteEmailNotifySubject).HasColumnName("NotifyTemplate_ReplyWriteEmailNotifySubject");
            template.Property(x => x.ReplyWriteEmailNotifyContent).HasColumnName("NotifyTemplate_ReplyWriteEmailNotifyContent");
        });

        builder.OwnsOne(x => x.Exp, exp =>
        {
            exp.Property(x => x.EnableExp).HasColumnName("Exp_EnableExp");
            exp.Property(x => x.ShowExpGuide).HasColumnName("Exp_ShowExpGuide");
            exp.Property(x => x.PostWriteExp).HasColumnName("Exp_PostWriteExp");
            exp.Property(x => x.CommentWriteExp).HasColumnName("Exp_CommentWriteExp");
            exp.Property(x => x.FileUploadExp).HasColumnName("Exp_FileUploadExp");
            exp.Property(x => x.FileDownloadExp).HasColumnName("Exp_FileDownloadExp");
            exp.Property(x => x.OtherPostReadExp).HasColumnName("Exp_OtherPostReadExp");
            exp.Property(x => x.OtherPostLikeExp).HasColumnName("Exp_OtherPostLikeExp");
            exp.Property(x => x.OtherPostDisLikeExp).HasColumnName("Exp_OtherPostDisLikeExp");
            exp.Property(x => x.OtherCommentLikeExp).HasColumnName("Exp_OtherCommentLikeExp");
            exp.Property(x => x.OtherCommentDisLikeExp).HasColumnName("Exp_OtherCommentDisLikeExp");
            exp.Property(x => x.OwnPostReadExp).HasColumnName("Exp_OwnPostReadExp");
            exp.Property(x => x.OwnPostLikeExp).HasColumnName("Exp_OwnPostLikeExp");
            exp.Property(x => x.OwnPostDisLikeExp).HasColumnName("Exp_OwnPostDisLikeExp");
            exp.Property(x => x.OwnCommentLikeExp).HasColumnName("Exp_OwnCommentLikeExp");
            exp.Property(x => x.OwnCommentDisLikeExp).HasColumnName("Exp_OwnCommentDisLikeExp");
            exp.Property(x => x.PostWriteUndoExp).HasColumnName("Exp_PostWriteUndoExp");
            exp.Property(x => x.CommentWriteUndoExp).HasColumnName("Exp_CommentWriteUndoExp");
            exp.Property(x => x.FileUploadUndoExp).HasColumnName("Exp_FileUploadUndoExp");
            exp.Property(x => x.OtherPostReadUndoExp).HasColumnName("Exp_OtherPostReadUndoExp");
            exp.Property(x => x.OtherPostLikeUndoExp).HasColumnName("Exp_OtherPostLikeUndoExp");
            exp.Property(x => x.OtherPostDisLikeUndoExp).HasColumnName("Exp_OtherPostDisLikeUndoExp");
            exp.Property(x => x.OtherCommentLikeUndoExp).HasColumnName("Exp_OtherCommentLikeUndoExp");
            exp.Property(x => x.OtherCommentDisLikeUndoExp).HasColumnName("Exp_OtherCommentDisLikeUndoExp");
            exp.Property(x => x.OwnPostReadUndoExp).HasColumnName("Exp_OwnPostReadUndoExp");
            exp.Property(x => x.OwnPostLikeUndoExp).HasColumnName("Exp_OwnPostLikeUndoExp");
            exp.Property(x => x.OwnPostDisLikeUndoExp).HasColumnName("Exp_OwnPostDisLikeUndoExp");
            exp.Property(x => x.OwnCommentLikeUndoExp).HasColumnName("Exp_OwnCommentLikeUndoExp");
            exp.Property(x => x.OwnCommentDisLikeUndoExp).HasColumnName("Exp_OwnCommentDisLikeUndoExp");
            exp.Property(x => x.PostWriteExpWithinDays).HasColumnName("Exp_PostWriteExpWithinDays");
            exp.Property(x => x.CommentWriteExpWithinDays).HasColumnName("Exp_CommentWriteExpWithinDays");
            exp.Property(x => x.FileUploadExpWithinDays).HasColumnName("Exp_FileUploadExpWithinDays");
            exp.Property(x => x.OtherPostReadExpWithinDays).HasColumnName("Exp_OtherPostReadExpWithinDays");
            exp.Property(x => x.OtherPostLikeExpWithinDays).HasColumnName("Exp_OtherPostLikeExpWithinDays");
            exp.Property(x => x.OtherPostDisLikeExpWithinDays).HasColumnName("Exp_OtherPostDisLikeExpWithinDays");
            exp.Property(x => x.OtherCommentLikeExpWithinDays).HasColumnName("Exp_OtherCommentLikeExpWithinDays");
            exp.Property(x => x.OtherCommentDisLikeExpWithinDays).HasColumnName("Exp_OtherCommentDisLikeExpWithinDays");
            exp.Property(x => x.OwnPostReadExpWithinDays).HasColumnName("Exp_OwnPostReadExpWithinDays");
            exp.Property(x => x.OwnPostLikeExpWithinDays).HasColumnName("Exp_OwnPostLikeExpWithinDays");
            exp.Property(x => x.OwnPostDisLikeExpWithinDays).HasColumnName("Exp_OwnPostDisLikeExpWithinDays");
            exp.Property(x => x.OwnCommentLikeExpWithinDays).HasColumnName("Exp_OwnCommentLikeExpWithinDays");
            exp.Property(x => x.OwnCommentDisLikeExpWithinDays).HasColumnName("Exp_OwnCommentDisLikeExpWithinDays");
        });

        builder.ToTable(nameof(BoardMeta), x => x.HasComment("게시판 설정"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
        builder.Property(x => x.BoardID).IsRequired().HasComment("게시판 ID");
    }
}
