using Domain.Entities.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure.Persistence.Configurations.Common;

public sealed class ConfigConfiguration : IEntityTypeConfiguration<Config>
{
    public void Configure(EntityTypeBuilder<Config> builder)
    {
        builder.ToTable(nameof(Config), x => x.HasComment("운영 정보 설정 값"));

        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
        builder.Property(x => x.LastUpdatedAt).IsRequired().HasComment("마지막 수정일시");
        builder.Property(x => x.RowVersion).IsRowVersion().HasComment("동시성 제어용");

        builder.OwnsOne(x => x.Basic, owned =>
        {
            owned.Property(x => x.SiteName).HasMaxLength(100).HasColumnName("Basic_SiteName").HasComment("사이트 이름");
            owned.Property(x => x.SiteURL).HasMaxLength(100).HasColumnName("Basic_SiteURL").HasComment("사이트 주소");
            owned.Property(x => x.RootID).HasMaxLength(100).HasColumnName("Basic_RootID").HasComment("최고 관리자 ID");
            owned.Property(x => x.FromEmail).HasMaxLength(100).HasColumnName("Basic_FromEmail").HasComment("송수신 이메일");
            owned.Property(x => x.FromName).HasMaxLength(30).HasColumnName("Basic_FromName").HasComment("송수신자 이름");
            owned.Property(x => x.SmtpServer).HasMaxLength(200).HasColumnName("Basic_SmtpServer").HasComment("SMTP Server");
            owned.Property(x => x.SmtpPort).HasColumnName("Basic_SmtpPort").HasComment("SMTP Port");
            owned.Property(x => x.SmtpEnableSSL).HasColumnName("Basic_SmtpEnableSSL").HasComment("SMTP Enable SSL");
            owned.Property(x => x.SmtpUsername).HasMaxLength(100).HasColumnName("Basic_SmtpUsername").HasComment("SMTP Username");
            owned.Property(x => x.SmtpPassword).HasMaxLength(200).HasColumnName("Basic_SmtpPassword").HasComment("SMTP Password");
            owned.Property(x => x.AdminWhiteIPList).HasMaxLength(1000).HasColumnName("Basic_AdminWhiteIPList").HasComment("관리자단 접근 가능 IP");
            owned.Property(x => x.FrontWhiteIPList).HasMaxLength(1000).HasColumnName("Basic_FrontWhiteIPList").HasComment("사용자단 접근 가능 IP");
            owned.Property(x => x.BlockAlertTitle).HasMaxLength(200).HasColumnName("Basic_BlockAlertTitle").HasComment("차단 시 안내문 제목");
            owned.Property(x => x.BlockAlertContent).HasMaxLength(5000).HasColumnName("Basic_BlockAlertContent").HasComment("차단 시 안내문 내용");
            owned.Property(x => x.IsMaintenance).HasColumnName("Basic_IsMaintenance").HasComment("점검 여부");
            owned.Property(x => x.MaintenanceContent).HasMaxLength(5000).HasColumnName("Basic_MaintenanceContent").HasComment("점검 내용");
        });

        builder.OwnsOne(x => x.Images, owned =>
        {
            owned.Property(x => x.Favicon).HasMaxLength(255).HasColumnName("Images_Favicon").HasComment("Favicon");
            owned.Property(x => x.LogoSquare).HasMaxLength(255).HasColumnName("Images_LogoSquare").HasComment("Logo-square");
            owned.Property(x => x.LogoHorizontal).HasMaxLength(255).HasColumnName("Images_LogoHorizontal").HasComment("Logo-horizontal");
            owned.Property(x => x.OgDefault).HasMaxLength(255).HasColumnName("Images_OgDefault").HasComment("og-default");
            owned.Property(x => x.TwitterImage).HasMaxLength(255).HasColumnName("Images_TwitterImage").HasComment("Twitter-image");
            owned.Property(x => x.AppleTouchIcon).HasMaxLength(255).HasColumnName("Images_AppleTouchIcon").HasComment("Apple-touch-icon");
            owned.Property(x => x.AppIcon_192).HasMaxLength(255).HasColumnName("Images_AppIcon_192").HasComment("App-icon-192");
            owned.Property(x => x.AppIcon_512).HasMaxLength(255).HasColumnName("Images_AppIcon_512").HasComment("App-icon-512");
        });

        builder.OwnsOne(x => x.Meta, owned =>
        {
            owned.Property(x => x.Keywords).HasMaxLength(255).HasColumnName("Meta_Keywords").HasComment("Meta Keywords");
            owned.Property(x => x.Description).HasMaxLength(255).HasColumnName("Meta_Description").HasComment("Meta Description");
            owned.Property(x => x.Author).HasMaxLength(255).HasColumnName("Meta_Author").HasComment("Meta Author");
            owned.Property(x => x.Viewport).HasMaxLength(255).HasColumnName("Meta_Viewport").HasComment("Meta Viewport");
            owned.Property(x => x.ApplicationName).HasMaxLength(255).HasColumnName("Meta_ApplicationName").HasComment("Meta Application Name");
            owned.Property(x => x.Generator).HasMaxLength(255).HasColumnName("Meta_Generator").HasComment("Meta Generator");
            owned.Property(x => x.Robots).HasMaxLength(255).HasColumnName("Meta_Robots").HasComment("Meta Robots");
        });

        builder.OwnsOne(x => x.Company, owned =>
        {
            owned.Property(x => x.Name).HasMaxLength(70).HasColumnName("Company_Name").HasComment("상호 명");
            owned.Property(x => x.RegNo).HasMaxLength(100).HasColumnName("Company_RegNo").HasComment("사업자 등록 번호");
            owned.Property(x => x.Address).HasMaxLength(255).HasColumnName("Company_Address").HasComment("사업장 소재지");
            owned.Property(x => x.ZipCode).HasMaxLength(8).HasColumnName("Company_ZipCode").HasComment("사업장 주소(우편번호)");
            owned.Property(x => x.Owner).HasMaxLength(50).HasColumnName("Company_Owner").HasComment("대표자 명");
            owned.Property(x => x.Tel).HasMaxLength(20).HasColumnName("Company_Tel").HasComment("대표 전화번호");
            owned.Property(x => x.Fax).HasMaxLength(20).HasColumnName("Company_Fax").HasComment("FAX");
            owned.Property(x => x.RetailSaleNo).HasMaxLength(20).HasColumnName("Company_RetailSaleNo").HasComment("통신판매업 신고번호");
            owned.Property(x => x.AddedSaleNo).HasMaxLength(20).HasColumnName("Company_AddedSaleNo").HasComment("부가통신 사업자번호");
            owned.Property(x => x.Hosting).HasMaxLength(100).HasColumnName("Company_Hosting").HasComment("호스팅 서비스");
            owned.Property(x => x.AdminName).HasMaxLength(70).HasColumnName("Company_AdminName").HasComment("정보관리책임자");
            owned.Property(x => x.AdminEmail).HasMaxLength(100).HasColumnName("Company_AdminEmail").HasComment("정보관리책임자 이메일");
            owned.Property(x => x.SiteUrl).HasMaxLength(200).HasColumnName("Company_SiteUrl").HasComment("사이트 주소");
            owned.Property(x => x.BankCode).HasMaxLength(10).HasColumnName("Company_BankCode").HasComment("입금계좌 - 은행");
            owned.Property(x => x.BankOwner).HasMaxLength(70).HasColumnName("Company_BankOwner").HasComment("입금계좌 - 예금주");
            owned.Property(x => x.BankNumber).HasMaxLength(100).HasColumnName("Company_BankNumber").HasComment("입금계좌 - 계좌번호");
        });

        builder.OwnsOne(x => x.Account, owned =>
        {
            owned.Property(x => x.IsRegisterBlock).HasColumnName("Account_IsRegisterBlock").HasComment("회원가입 차단");
            owned.Property(x => x.IsRegisterEmailAuth).HasColumnName("Account_IsRegisterEmailAuth").HasComment("회원가입 시 이메일 인증");
            owned.Property(x => x.PasswordMinLength).HasColumnName("Account_PasswordMinLength").HasComment("비밀번호 최소 길이");
            owned.Property(x => x.PasswordUppercaseLength).HasColumnName("Account_PasswordUppercaseLength").HasComment("비밀번호 최소 대문자 수");
            owned.Property(x => x.PasswordNumbersLength).HasColumnName("Account_PasswordNumbersLength").HasComment("비밀번호 최소 숫자 수");
            owned.Property(x => x.PasswordSpecialcharsLength).HasColumnName("Account_PasswordSpecialcharsLength").HasComment("비밀번호 최소 특수문자 수");
            owned.Property(x => x.DeniedEmailList).HasColumnName("Account_DeniedEmailList").HasComment("금지 이메일");
            owned.Property(x => x.DeniedNameList).HasColumnName("Account_DeniedNameList").HasComment("금지 별명");
            owned.Property(x => x.ChangeEmailDay).HasColumnName("Account_ChangeEmailDay").HasComment("이메일 갱신 주기(일)");
            owned.Property(x => x.ChangeNameDay).HasColumnName("Account_ChangeNameDay").HasComment("별명 갱신 주기(일)");
            owned.Property(x => x.ChangeSummaryDay).HasColumnName("Account_ChangeSummaryDay").HasComment("한마디 갱신 주기(일)");
            owned.Property(x => x.ChangeIntroDay).HasColumnName("Account_ChangeIntroDay").HasComment("자기소개 갱신 주기(일)");
            owned.Property(x => x.ChangePasswordDay).HasColumnName("Account_ChangePasswordDay").HasComment("비밀번호 갱신 주기(일)");
            owned.Property(x => x.MaxLoginTryCount).HasColumnName("Account_MaxLoginTryCount").HasComment("로그인 시도 제한 횟수");
            owned.Property(x => x.MaxLoginTryLimitSecond).HasColumnName("Account_MaxLoginTryLimitSecond").HasComment("로그인 시도 제한 시간(초)");
        });

        builder.OwnsOne(x => x.EmailTemplate, owned =>
        {
            owned.Property(x => x.RegisterEmailFormTitle).HasColumnName("EmailTemplate_RegisterEmailFormTitle").HasComment("회원가입 시 - 제목");
            owned.Property(x => x.RegisterEmailFormContent).HasColumnName("EmailTemplate_RegisterEmailFormContent").HasComment("회원가입 시 - 내용");
            owned.Property(x => x.RegistrationEmailFormTitle).HasColumnName("EmailTemplate_RegistrationEmailFormTitle").HasComment("회원가입 완료 - 제목");
            owned.Property(x => x.RegistrationEmailFormContent).HasColumnName("EmailTemplate_RegistrationEmailFormContent").HasComment("회원가입 완료 - 내용");
            owned.Property(x => x.ResetPasswordEmailFormTitle).HasColumnName("EmailTemplate_ResetPasswordEmailFormTitle").HasComment("비밀번호 재설정 - 제목");
            owned.Property(x => x.ResetPasswordEmailFormContent).HasColumnName("EmailTemplate_ResetPasswordEmailFormContent").HasComment("비밀번호 재설정 - 내용");
            owned.Property(x => x.ChangedPasswordEmailFormTitle).HasColumnName("EmailTemplate_ChangedPasswordEmailFormTitle").HasComment("비밀번호 변경 완료 - 제목");
            owned.Property(x => x.ChangedPasswordEmailFormContent).HasColumnName("EmailTemplate_ChangedPasswordEmailFormContent").HasComment("비밀번호 변경 완료 - 내용");
            owned.Property(x => x.WithdrawEmailFormTitle).HasColumnName("EmailTemplate_WithdrawEmailFormTitle").HasComment("회원탈퇴 시 - 제목");
            owned.Property(x => x.WithdrawEmailFormContent).HasColumnName("EmailTemplate_WithdrawEmailFormContent").HasComment("회원탈퇴 시 - 내용");
            owned.Property(x => x.EmailVerifyFormTitle).HasColumnName("EmailTemplate_EmailVerifyFormTitle").HasComment("이메일 변경 시 - 제목");
            owned.Property(x => x.EmailVerifyFormContent).HasColumnName("EmailTemplate_EmailVerifyFormContent").HasComment("이메일 변경 시 - 내용");
            owned.Property(x => x.ChangedEmailFormTitle).HasColumnName("EmailTemplate_ChangedEmailFormTitle").HasComment("이메일 변경 완료 - 제목");
            owned.Property(x => x.ChangedEmailFormContent).HasColumnName("EmailTemplate_ChangedEmailFormContent").HasComment("이메일 변경 완료 - 내용");
        });

        builder.OwnsOne(x => x.External, owned =>
        {
            owned.Property(x => x.YouTubeApiKeyEnc).HasColumnName("External_YouTubeApiKeyEnc").HasComment("YouTube API Key (암호화 저장 권장)");
            owned.Property(x => x.YouTubeApiName).HasColumnName("External_YouTubeApiName").HasComment("YouTube API Name");
            owned.Property(x => x.GoogleClientId).HasColumnName("External_GoogleClientId").HasComment("Google Client ID");
            owned.Property(x => x.GoogleClientSecretEnc).HasColumnName("External_GoogleClientSecretEnc").HasComment("Google Client Secret (암호화 저장 권장)");
            owned.Property(x => x.GoogleAppId).HasColumnName("External_GoogleAppId").HasComment("Google APP ID");
        });

        builder.OwnsOne(x => x.Payment, owned => {
            owned.Property(x => x.DanalCardFeeRate).HasPrecision(5, 2);
            owned.Property(x => x.DanalCardFeeAmount).HasPrecision(18, 0);
            owned.Property(x => x.DanalTransferFeeRate).HasPrecision(5, 2);
            owned.Property(x => x.DanalTransferFeeAmount).HasPrecision(18, 0);
            owned.Property(x => x.DanalVbankFeeRate).HasPrecision(5, 2);
            owned.Property(x => x.DanalVbankFeeAmount).HasPrecision(18, 0);
            owned.Property(x => x.DanalSimpleFeeRate).HasPrecision(5, 2);
            owned.Property(x => x.DanalSimpleFeeAmount).HasPrecision(18, 0);
        });

        builder.OwnsOne(x => x.Crypto, owned =>
        {
            owned.Property(x => x.TickerRefreshSeconds).IsRequired().HasColumnName("Crypto_TickerRefreshSeconds").HasDefaultValue(5).HasComment("시세 업데이트 주기 (초)");
            owned.Property(x => x.SurgeThreshold).IsRequired().HasColumnType("decimal(5,2)").HasColumnName("Crypto_SurgeThreshold").HasDefaultValue(5.0m).HasComment("급등 임계값 (%)");
            owned.Property(x => x.PlungeThreshold).IsRequired().HasColumnType("decimal(5,2)").HasColumnName("Crypto_PlungeThreshold").HasDefaultValue(-5.0m).HasComment("급락 임계값 (%)");
            owned.Property(x => x.MainPageCoinCount).IsRequired().HasColumnName("Crypto_MainPageCoinCount").HasDefaultValue(10).HasComment("메인 페이지 기본 표시 코인 수");
        });
    }
}