using System.Runtime.CompilerServices;

namespace KArtSell.Modules.ModelOperations;

/// <summary>
/// KArtSell.BuildingBlocks.Data.DapperBootstrap sets Dapper's snake_case-to-PascalCase column
/// mapping via its own [ModuleInitializer], but that only fires once that assembly is actually
/// loaded into the process. Several Sql classes in this module (e.g. AuditSql, TradeSql) only
/// have a `using` for a BuildingBlocks namespace without ever touching a type from it at
/// runtime, so under test isolation - or any host that queries this module before touching
/// BuildingBlocks - the load (and the mapping) can be skipped, silently nulling out every
/// snake_case column. Every Sql class in this assembly is defined here, so a module initializer
/// in this assembly is guaranteed to run before any of them are used, regardless of what else
/// has loaded.
/// </summary>
internal static class DapperMappingBootstrap
{
#pragma warning disable CA2255
    [ModuleInitializer]
#pragma warning restore CA2255
    public static void Initialize()
    {
        Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;
    }
}
