using System.Text.Json;
using Tiku.Domain.Tenancy;

namespace Tiku.Infrastructure.Tenancy;

internal static class TenantFrontendConfigDefaults
{
    public static TenantFrontendConfig Create(Guid tenantId, string tenantName)
    {
        var shortName = tenantName.Length <= 4 ? tenantName : tenantName[..4];
        var branding = JsonSerializer.SerializeToElement(new
        {
            brandName = tenantName,
            shortName,
            slogan = "让每一次学习都有方向",
            logoUrl = "",
            faviconUrl = "",
            serviceWechat = ""
        });
        var theme = JsonSerializer.SerializeToElement(new
        {
            primaryColor = "#3157d5",
            secondaryColor = "#20b486",
            backgroundColor = "#f5f7fb",
            textColor = "#172033",
            fontFamily = "system-ui, sans-serif",
            radius = 18
        });
        var features = JsonSerializer.SerializeToElement(new { template = "clarity" });
        var navigation = JsonSerializer.SerializeToElement(new[]
        {
            new { id = "home", label = "首页", href = "/", visible = true },
            new { id = "learning", label = "学习中心", href = "/learning", visible = true },
            new { id = "scoreline", label = "院校分数线", href = "/scoreline", visible = true },
            new { id = "profile", label = "个人中心", href = "/profile", visible = true }
        });
        var modules = JsonSerializer.SerializeToElement(new[]
        {
            new { id = "hero", type = "hero", title = "首页主视觉", visible = true },
            new { id = "announcement", type = "announcement", title = "最新公告", visible = true },
            new { id = "features", type = "feature-grid", title = "学习服务", visible = true },
            new { id = "subjects", type = "subject-entry", title = "热门学科", visible = true },
            new { id = "scoreline", type = "scoreline-entry", title = "院校分数线", visible = true },
            new { id = "store", type = "store-entry", title = "精选课程", visible = true },
            new { id = "contact", type = "contact-cta", title = "学习顾问", visible = true }
        });

        return new TenantFrontendConfig
        {
            TenantId = tenantId,
            SchemaVersion = 1,
            ConfigVersion = 1,
            PublishedBranding = branding.Clone(),
            PublishedTheme = theme.Clone(),
            PublishedFeatures = features.Clone(),
            PublishedNavigation = navigation.Clone(),
            PublishedHomeModules = modules.Clone(),
            DraftBranding = branding.Clone(),
            DraftTheme = theme.Clone(),
            DraftFeatures = features.Clone(),
            DraftNavigation = navigation.Clone(),
            DraftHomeModules = modules.Clone()
        };
    }
}