using Microsoft.Extensions.Options; namespace NeonSprawl.Server.Game.PositionState; /// Runs DDL and dev-player seed once when the host starts (PostgreSQL path only). internal sealed class PostgresDevPlayerSeedHostedService : IHostedService { private readonly Npgsql.NpgsqlDataSource _dataSource; private readonly GamePositionOptions _options; public PostgresDevPlayerSeedHostedService( Npgsql.NpgsqlDataSource dataSource, IOptions options) { _dataSource = dataSource; var o = options.Value; if (string.IsNullOrWhiteSpace(o.DevPlayerId)) { throw new InvalidOperationException("Game:DevPlayerId must be non-empty."); } _options = o; } public Task StartAsync(CancellationToken cancellationToken) { PostgresPositionBootstrap.EnsureSchema(_dataSource); PostgresPositionBootstrap.SeedDevPlayer(_dataSource, _options); return Task.CompletedTask; } public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; }