using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using Tiku.Domain.Common;
using Tiku.Domain.Tenancy;

namespace Tiku.Api.Contracts;

/// <summary>
/// 租户解析查询参数。
/// </summary>
public sealed class TenantResolveQueryDto
{
    /// <summary>
    /// 访问域名。
    /// </summary>
    [StringLength(253)]
    [Description("要解析的访问域名，例如 student.example.com。本地开发也可以直接传 localhost。")]
    public string? Host { get; set; }

    /// <summary>
    /// 租户编码。
    /// </summary>
    [StringLength(100)]
    [Description("租户编码；本地开发或无独立域名时使用，例如 master。")]
    public string? TenantCode { get; set; }
}

/// <summary>
/// 租户解析响应。
/// </summary>
/// <param name="Tenant">公开租户基础信息。</param>
/// <param name="Branding">公开品牌配置。</param>
/// <param name="Features">面向前端公开的功能开关。</param>
/// <param name="AdminFeatures">面向管理端公开的功能开关。</param>
/// <param name="PublicConfig">可公开的租户配置，不包含密钥或内部配置。</param>
/// <summary>
/// 租户解析Response请求 DTO。
/// </summary>
public sealed record TenantResolveResponseDto(
    PublicTenantDto Tenant,
    PublicTenantBrandingDto Branding,
    JsonElement Features,
    JsonElement AdminFeatures,
    JsonElement PublicConfig);

/// <summary>
/// 可公开给客户端的租户基础信息。
/// </summary>
/// <param name="Id">租户 ID。</param>
/// <param name="Slug">租户编码。</param>
/// <param name="Name">租户名称。</param>
/// <param name="Status">租户状态。</param>
/// <param name="Mode">租户模式。</param>
/// <param name="Host">当前匹配到的访问域名。</param>
/// <summary>
/// 公开租户请求 DTO。
/// </summary>
public sealed record PublicTenantDto(
    Guid Id,
    string Slug,
    string Name,
    TenantStatus Status,
    TenantMode Mode,
    string? Host);

/// <summary>
/// 可公开给客户端的租户品牌信息。
/// </summary>
/// <param name="BrandName">品牌名称。</param>
/// <param name="ShortName">品牌短名称。</param>
/// <param name="Slogan">品牌标语。</param>
/// <param name="LogoUrl">Logo 地址。</param>
/// <param name="FaviconUrl">Favicon 地址。</param>
/// <param name="ServiceWechat">客服微信。</param>
/// <param name="ServiceAccountName">公众号或服务号名称。</param>
/// <param name="Theme">公开主题配置。</param>
/// <param name="PublicAssets">公开资源配置。</param>
/// <summary>
/// 公开租户品牌请求 DTO。
/// </summary>
public sealed record PublicTenantBrandingDto(
    string? BrandName,
    string? ShortName,
    string? Slogan,
    string? LogoUrl,
    string? FaviconUrl,
    string? ServiceWechat,
    string? ServiceAccountName,
    JsonElement Theme,
    JsonElement PublicAssets)
{
    public static PublicTenantBrandingDto Empty { get; } = new(
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        JsonDefaults.Object(),
        JsonDefaults.Object());
}
