using Microsoft.Extensions.Options; using NeonSprawl.Server.Game.Encounters; using NeonSprawl.Server.Game.Factions; using NeonSprawl.Server.Game.Skills; namespace NeonSprawl.Server.Game.Contracts; /// DI registration for the fail-fast contract template catalog (NEO-145). public static class ContractCatalogServiceCollectionExtensions { /// Binds and registers and as singletons. public static IServiceCollection AddContractTemplateCatalog(this IServiceCollection services, IConfiguration configuration) { services.AddOptions() .Bind(configuration.GetSection(ContentPathsOptions.SectionName)); services.AddSingleton(sp => { var hostEnv = sp.GetRequiredService(); var opts = sp.GetRequiredService>().Value; var encounterCatalog = sp.GetRequiredService(); var skillCatalog = sp.GetRequiredService(); var factionCatalog = sp.GetRequiredService(); var logger = sp.GetRequiredService() .CreateLogger("NeonSprawl.Server.Game.Contracts.ContractCatalog"); var contractsDir = ContractCatalogPathResolution.ResolveContractsDirectory( opts.ContractsDirectory, hostEnv.ContentRootPath); var contractTemplateSchemaPath = ContractCatalogPathResolution.ResolveContractTemplateSchemaPath( contractsDir, opts.ContractTemplateSchemaPath, hostEnv.ContentRootPath); var rewardGrantRowSchemaPath = ContractCatalogPathResolution.ResolveRewardGrantRowSchemaPath(contractsDir); var questSkillXpGrantSchemaPath = ContractCatalogPathResolution.ResolveQuestSkillXpGrantSchemaPath(contractsDir); var questRewardBundleSchemaPath = ContractCatalogPathResolution.ResolveQuestRewardBundleSchemaPath(contractsDir); var factionGateRuleSchemaPath = ContractCatalogPathResolution.ResolveFactionGateRuleSchemaPath(contractsDir); var reputationGrantRowSchemaPath = ContractCatalogPathResolution.ResolveReputationGrantRowSchemaPath(contractsDir); var knownEncounterIds = encounterCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal); var knownFactionIds = factionCatalog.ById.Keys.ToHashSet(StringComparer.Ordinal); return ContractTemplateCatalogLoader.Load( contractsDir, contractTemplateSchemaPath, rewardGrantRowSchemaPath, questSkillXpGrantSchemaPath, questRewardBundleSchemaPath, factionGateRuleSchemaPath, reputationGrantRowSchemaPath, knownEncounterIds, knownFactionIds, skillCatalog.ById, logger); }); services.AddSingleton(sp => new ContractTemplateRegistry(sp.GetRequiredService())); return services; } }