using Mapster;
using MapsterMapper;
using Microsoft.Extensions.DependencyInjection;

namespace HoneyBox.Core.Mappings;

/// <summary>
/// Mapster 对象映射配置类
/// </summary>
public static class MappingConfig
{
    /// <summary>
    /// 配置 Mapster 映射规则
    /// </summary>
    public static void Configure()
    {
        // 全局配置
        TypeAdapterConfig.GlobalSettings.Default
            .IgnoreNullValues(true)
            .PreserveReference(true);

        // 在此处添加自定义映射配置
        // 示例：
        // TypeAdapterConfig<Source, Destination>.NewConfig()
        //     .Map(dest => dest.FullName, src => $"{src.FirstName} {src.LastName}");
    }

    /// <summary>
    /// 注册 Mapster 服务到依赖注入容器
    /// </summary>
    /// <param name="services">服务集合</param>
    /// <returns>服务集合</returns>
    public static IServiceCollection AddMapsterConfiguration(this IServiceCollection services)
    {
        // 配置映射规则
        Configure();

        // 注册 TypeAdapterConfig 和 IMapper
        var config = TypeAdapterConfig.GlobalSettings;
        services.AddSingleton(config);
        services.AddScoped<IMapper, ServiceMapper>();

        return services;
    }
}
