namespace NeonSprawl.Server.Game.Contracts; /// Resolves contract catalog paths for local dev, tests, and container layouts (NEO-145). public static class ContractCatalogPathResolution { /// Walks and parents for an existing content/contracts directory. public static string? TryDiscoverContractsDirectory(string startDirectory) { for (var dir = new DirectoryInfo(startDirectory); dir is not null; dir = dir.Parent) { var candidate = Path.Combine(dir.FullName, "content", "contracts"); if (Directory.Exists(candidate)) return Path.GetFullPath(candidate); } return null; } /// /// Resolves the contracts catalog directory. /// Empty triggers discovery from . /// public static string ResolveContractsDirectory(string? configuredContractsDirectory, string contentRootPath) { if (string.IsNullOrWhiteSpace(configuredContractsDirectory)) { var discovered = TryDiscoverContractsDirectory(AppContext.BaseDirectory); if (discovered is not null) return discovered; throw new InvalidOperationException( "Content:ContractsDirectory is not set and auto-discovery failed (no ancestor of AppContext.BaseDirectory contains 'content/contracts'). " + "Set Content:ContractsDirectory in configuration or environment (e.g. Content__ContractsDirectory)."); } var trimmed = configuredContractsDirectory.Trim(); if (Path.IsPathRooted(trimmed)) return Path.GetFullPath(trimmed); return Path.GetFullPath(Path.Combine(contentRootPath, trimmed)); } /// Resolves JSON Schema path for a single contract template row (Draft 2020-12). public static string ResolveContractTemplateSchemaPath( string contractsDirectory, string? configuredSchemaPath, string contentRootPath) { if (!string.IsNullOrWhiteSpace(configuredSchemaPath)) { var trimmed = configuredSchemaPath.Trim(); if (Path.IsPathRooted(trimmed)) return Path.GetFullPath(trimmed); return Path.GetFullPath(Path.Combine(contentRootPath, trimmed)); } return Path.GetFullPath(Path.Combine(contractsDirectory, "..", "schemas", "contract-template.schema.json")); } /// Resolves JSON Schema path for a reward grant row (shared by quest bundles and contract templates). public static string ResolveRewardGrantRowSchemaPath(string contractsDirectory) => Path.GetFullPath(Path.Combine(contractsDirectory, "..", "schemas", "reward-grant-row.schema.json")); /// Resolves JSON Schema path for a quest skill XP grant row. public static string ResolveQuestSkillXpGrantSchemaPath(string contractsDirectory) => Path.GetFullPath(Path.Combine(contractsDirectory, "..", "schemas", "quest-skill-xp-grant.schema.json")); /// Resolves JSON Schema path for a completion reward bundle. public static string ResolveQuestRewardBundleSchemaPath(string contractsDirectory) => Path.GetFullPath(Path.Combine(contractsDirectory, "..", "schemas", "quest-reward-bundle.schema.json")); /// Resolves JSON Schema path for a faction gate rule row. public static string ResolveFactionGateRuleSchemaPath(string contractsDirectory) => Path.GetFullPath(Path.Combine(contractsDirectory, "..", "schemas", "faction-gate-rule.schema.json")); /// Resolves JSON Schema path for a reputation grant row. public static string ResolveReputationGrantRowSchemaPath(string contractsDirectory) => Path.GetFullPath(Path.Combine(contractsDirectory, "..", "schemas", "reputation-grant-row.schema.json")); }