using Tiku.Application;
using Tiku.Application.Tenancy;
using Tiku.Infrastructure;
using Tiku.Worker;

var builder = Host.CreateApplicationBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("Database")
    ?? builder.Configuration["DATABASE_URL"]
    ?? throw new InvalidOperationException(
        "Database connection is required. Configure ConnectionStrings:Database or DATABASE_URL.");
builder.Services.AddApplication();
builder.Services.AddInfrastructure(connectionString);
builder.Services.AddOptions<DomainLifecycleOptions>()
    .Bind(builder.Configuration.GetSection("TenantDomains"));
builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();
