using Microsoft.Extensions.Configuration; using Microsoft.Data.SqlClient; using PlotLine.Data; using System.Text.Json; using System.Security.Cryptography; if(args.Length!=3 || args[1] is not ("PlotDirector_Development" or "PlotLine"))throw new ArgumentException("Usage: PublicPricing PRIVATE_CONFIG_JSON EXPECTED_DATABASE NEW_OUTPUT_DIRECTORY"); var output=Path.GetFullPath(args[2]);if(Directory.Exists(output))throw new IOException("Output must be new"); var config=new ConfigurationBuilder().AddJsonFile(Path.GetFullPath(args[0]),optional:false).Build(); var connection=new SqlConnectionStringBuilder(config.GetConnectionString("DefaultConnection")); if(connection.InitialCatalog!=args[1])throw new InvalidOperationException("Configured database differs from explicit approved target"); using(var verify=new SqlConnection(connection.ConnectionString)){await verify.OpenAsync();if(verify.Database!=args[1])throw new InvalidOperationException("Wrong actual database");} // Same authoritative read-only stored procedure used by the application's subscription service. var levels=await new SubscriptionRepository(new SqlConnectionFactory(config)).GetActiveSubscriptionLevelsAsync(); var plans=levels.Select(p=>new {p.SubscriptionLevelID,p.Name,p.DisplayName,p.Description,p.MaxBooks,p.MaxChaptersPerBook,p.MaxScenesPerBook,p.MaxCharactersPerProject,p.MaxStorageMB,p.MaxCollaborators,p.IsActive,p.SortOrder,p.RequiresStripeSubscription,p.BillingInterval,p.MonthlyPricePence,p.AnnualPricePence,p.CurrencyCode}).ToArray(); Directory.CreateDirectory(output);var file=Path.Combine(output,"pricing.json");await File.WriteAllTextAsync(file,JsonSerializer.Serialize(plans,new JsonSerializerOptions{WriteIndented=true})+"\n"); await File.WriteAllTextAsync(Path.Combine(output,"manifest.json"),JsonSerializer.Serialize(new {format=1,kind="public-pricing",sourceDatabase=args[1],exportedUtc=DateTime.UtcNow,storedProcedure="dbo.SubscriptionLevel_ListActive",sha256=Convert.ToHexString(SHA256.HashData(await File.ReadAllBytesAsync(file))).ToLowerInvariant()},new JsonSerializerOptions{WriteIndented=true})+"\n"); Console.WriteLine($"Exported {plans.Length} public plans; no database or provider changes. Review and publish independently.");