using Domain.Entities.Forum.Constants;
using Domain.Entities.Forum.ValueObject;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;

namespace Domain.Entities.Forum.Boards
{
    public class BoardMeta
    {
        [Key]
        public int ID { get; set; }

        public int BoardID { get; set; }

        // 목록
        public BoardMetaList List { get; set; } = new BoardMetaList();

        // 열람
        public BoardMetaView View { get; set; } = new BoardMetaView();

        // 작성
        public BoardMetaWrite Write { get; set; } = new BoardMetaWrite();

        // 댓글
        public BoardMetaComment Comment { get; set; } = new BoardMetaComment();

        // 일반
        public BoardMetaGeneral General { get; set; } = new BoardMetaGeneral();

        // 권한
        public BoardMetaPermission Permission { get; set; } = new BoardMetaPermission();

        // 알람
        public BoardMetaNotify Notify { get; set; } = new BoardMetaNotify();

        // 알람 양식
        public BoardMetaNotifyTemplate NotifyTemplate { get; set; } = new BoardMetaNotifyTemplate();

        // 경험치
        public BoardMetaExp Exp { get; set; } = new BoardMetaExp();
    }

    /// <summary>
    /// 게시판 목록 설정
    /// </summary>
    [Owned]
    public class BoardMetaList
    {
        public bool ShowHeader { get; set; } = false;

        public string? HeaderContent { get; set; }

        public bool ShowFooter { get; set; } = false;

        public string? FooterContent { get; set; }

        public BoardLayout? Layout { get; set; }

        public BoardSort? Sort { get; set; }

        public byte PerPage { get; set; } = 0;

        public bool AlwaysShowWriteButton { get; set; } = false;

        public bool ShowFooterListView { get; set; } = false;

        public bool IsNewIcon { get; set; } = false;

        public bool IsHotIcon { get; set; } = false;

        public bool ExceptNotice { get; set; } = false;

        public bool ExceptSpeaker { get; set; } = false;
    }

    /// <summary>
    /// 게시판 열람 설정
    /// </summary>
    [Owned]
    public class BoardMetaView
    {
        public bool AllowBookmark { get; set; } = false;

        public bool AllowLike { get; set; } = false;

        public bool AllowDislike { get; set; } = false;

        public bool AllowPrint { get; set; } = false;

        public bool AllowSnsShare { get; set; } = false;

        public bool AllowPrevNextBotton { get; set; } = false;

        public bool AllowBlame { get; set; } = false;

        public ushort BlameHideCount { get; set; } = 0;

        public bool AllowContentLinkTargetBlank { get; set; } = false;

        public bool AllowPostUrlCopy { get; set; } = false;

        public bool AllowPostUrlQrCode { get; set; } = false;

        public bool ShowMemberThumb { get; set; } = false;

        public bool ShowMemberIcon { get; set; } = false;

        public bool ShowMemberRegDate { get; set; } = false;

        public bool ShowMemberSummary { get; set; } = false;
    }

    /// <summary>
    /// 게시판 작성 설정
    /// </summary>
    [Owned]
    public class BoardMetaWrite
    {
        public bool ShowHeader { get; set; } = false;

        public string? HeaderContent { get; set; }

        public bool ShowFooter { get; set; } = false;

        public string? FooterContent { get; set; }

        public string? DefaultSubject { get; set; }

        public string? DefaultContent { get; set; }

        public bool AllowEditor { get; set; } = false;

        public bool AllowPrefix { get; set; } = false;

        public bool RequiredPrefix { get; set; } = false;

        public bool AllowSecret { get; set; } = false;

        public bool AllowTag { get; set; } = false;

        public byte TagLimit { get; set; } = PostConstant.MaxAllowedTags;

        public bool AllowImage { get; set; } = false;

        public byte ImageUploadLimit { get; set; } = PostConstant.MaxAllowedImages;

        public int ImageUploadMaxSize { get; set; } = PostConstant.MaxAllowedImageSize;

        public bool AllowMedia { get; set; } = false;

        public byte MediaUploadLimit { get; set; } = PostConstant.MaxAllowedMedias;

        public bool AllowFile { get; set; } = false;

        public byte FileUploadLimit { get; set; } = PostConstant.MaxAllowedFiles;

        public int FileUploadMaxSize { get; set; } = PostConstant.MaxAllowedFileSize;

        public string? FileUploadExtension { get; set; }
    }

    /// <summary>
    /// 게시판 일반 설정
    /// </summary>
    [Owned]
    public class BoardMetaGeneral
    {
        public ushort DeleteProtectionDays { get; set; } = 0;

        public ushort UpdateProtectionDays { get; set; } = 0;

        public bool AllowDeleteProtection { get; set; } = false;

        public bool AllowUpdateProtection { get; set; } = false;

        public bool EnableFileDownLog { get; set; } = false;

        public bool EnableLinkClickLog { get; set; } = false;

        public bool EnablePostUpdateLog { get; set; } = false;
    }

    /// <summary>
    /// 게시판 권한 설정
    /// </summary>
    [Owned]
    public class BoardMetaPermission
    {
        public short BoardAccess { get; set; } = (short)BoardPermission.Guest;

        public short PostView { get; set; } = (short)BoardPermission.Guest;

        public short PostWrite { get; set; } = (short)BoardPermission.Guest;

        public short CommentView { get; set; } = (short)BoardPermission.Guest;

        public short CommentWrite { get; set; } = (short)BoardPermission.Guest;

        public short ReplyWrite { get; set; } = (short)BoardPermission.Guest;

        public short FileUpload { get; set; } = (short)BoardPermission.Guest;

        public short FileDownload { get; set; } = (short)BoardPermission.Guest;
    }

    /// <summary>
    /// 게시판 알림 설정
    /// </summary>
    [Owned]
    public class BoardMetaNotify
    {
        public byte? PostWriteNotify { get; set; }

        public byte? CommentWriteNotify { get; set; }

        public byte? ReplyWriteNotify { get; set; }

        public BoardNotify PostWriteNotifyEnum => (BoardNotify)(PostWriteNotify ?? 0);
        public BoardNotify CommentWriteNotifyEnum => (BoardNotify)(CommentWriteNotify ?? 0);
        public BoardNotify ReplyWriteNotifyEnum => (BoardNotify)(ReplyWriteNotify ?? 0);
    }

    /// <summary>
    /// 게시판 경험치 설정
    /// </summary>
    [Owned]
    public class BoardMetaExp
    {
        public bool EnableExp { get; set; } = false;

        public bool ShowExpGuide { get; set; } = false;

        /*
         * 경험치 지급량 조절
         */
        public ushort PostWriteExp { get; set; } = 0;

        public ushort CommentWriteExp { get; set; } = 0;

        public ushort FileUploadExp { get; set; } = 0;

        public short FileDownloadExp { get; set; } = 0;

        public short OtherPostReadExp { get; set; } = 0;

        public ushort OtherPostLikeExp { get; set; } = 0;

        public ushort OtherPostDisLikeExp { get; set; } = 0;

        public ushort OtherCommentLikeExp { get; set; } = 0;

        public ushort OtherCommentDisLikeExp { get; set; } = 0;

        public ushort OwnPostReadExp { get; set; } = 0;

        public ushort OwnPostLikeExp { get; set; } = 0;

        public short OwnPostDisLikeExp { get; set; } = 0;

        public ushort OwnCommentLikeExp { get; set; } = 0;

        public short OwnCommentDisLikeExp { get; set; } = 0;

        /*
         * 경험치 회수량 조절 (항상 음수 계산)
         */
        public ushort PostWriteUndoExp { get; set; } = 0;

        public ushort CommentWriteUndoExp { get; set; } = 0;

        public ushort FileUploadUndoExp { get; set; } = 0;

        public ushort OtherPostReadUndoExp { get; set; } = 0;

        public ushort OtherPostLikeUndoExp { get; set; } = 0;

        public ushort OtherPostDisLikeUndoExp { get; set; } = 0;

        public ushort OtherCommentLikeUndoExp { get; set; } = 0;

        public ushort OtherCommentDisLikeUndoExp { get; set; } = 0;

        public ushort OwnPostReadUndoExp { get; set; } = 0;

        public ushort OwnPostLikeUndoExp { get; set; } = 0;

        public ushort OwnPostDisLikeUndoExp { get; set; } = 0;

        public ushort OwnCommentLikeUndoExp { get; set; } = 0;

        public ushort OwnCommentDisLikeUndoExp { get; set; } = 0;

        /*
         * 경험치 지급 기한
         */
        public ushort PostWriteExpWithinDays { get; set; } = 0;

        public ushort CommentWriteExpWithinDays { get; set; } = 0;

        public ushort FileUploadExpWithinDays { get; set; } = 0;

        public ushort OtherPostReadExpWithinDays { get; set; } = 0;

        public ushort OtherPostLikeExpWithinDays { get; set; } = 0;

        public ushort OtherPostDisLikeExpWithinDays { get; set; } = 0;

        public ushort OtherCommentLikeExpWithinDays { get; set; } = 0;

        public ushort OtherCommentDisLikeExpWithinDays { get; set; } = 0;

        public ushort OwnPostReadExpWithinDays { get; set; } = 0;

        public ushort OwnPostLikeExpWithinDays { get; set; } = 0;

        public ushort OwnPostDisLikeExpWithinDays { get; set; } = 0;

        public ushort OwnCommentLikeExpWithinDays { get; set; } = 0;

        public ushort OwnCommentDisLikeExpWithinDays { get; set; } = 0;
    }

    /// <summary>
    /// 게시판 알림 양식
    /// </summary>
    [Owned]
    public class BoardMetaNotifyTemplate
    {
        public string? PostWriteEmailNotifySubject { get; set; }

        public string? PostWriteEmailNotifyContent { get; set; }

        public string? CommentWriteEmailNotifySubject { get; set; }

        public string? CommentWriteEmailNotifyContent { get; set; }

        public string? ReplyWriteEmailNotifySubject { get; set; }

        public string? ReplyWriteEmailNotifyContent { get; set; }
    }

    /// <summary>
    /// 게시판 댓글 설정
    /// </summary>
    [Owned]
    public class BoardMetaComment
    {
        public bool EnableComment { get; set; } = false;

        public ushort PerPage { get; set; } = 0;

        public bool AllowLike { get; set; } = false;

        public bool AllowDisLike { get; set; } = false;

        public bool ShowMemberThumb { get; set; } = false;

        public bool ShowMemberIcon { get; set; } = false;

        public string? ContentPlaceholder { get; set; }

        public ushort MinContentLength { get; set; } = 0;

        public ushort MaxContentLength { get; set; } = 0;

        public bool EnableEditor { get; set; } = false;

        public bool AllowSecret { get; set; } = false;

        public ushort BlameHideCount { get; set; } = 0;

        public ushort DeleteProtectionDays { get; set; } = 0;

        public ushort UpdateProtectionDays { get; set; } = 0;

        public bool AllowDeleteProtection { get; set; } = false;

        public bool AllowUpdateProtection { get; set; } = false;

        public bool EnableCommentUpdateLog { get; set; } = false;
    }
}