using Microsoft.AspNetCore.ResponseCompression;
using SummerBestWebForm2.ClassObj;
using SummerBestWebForm2.Components;
using System.IO.Compression;

namespace SummerBestWebForm2
{
  public class Program
  {
    public static void Main(string[] args)
    {
      var builder = WebApplication.CreateBuilder(args);

      // Add services to the container.
      builder.Services.AddRazorComponents()
          .AddInteractiveServerComponents();

      builder.Services.AddResponseCompression(options =>
      {
        options.EnableForHttps = true;
        options.Providers.Add<BrotliCompressionProvider>();
        options.Providers.Add<GzipCompressionProvider>();
      });
      builder.Services.Configure<BrotliCompressionProviderOptions>(options =>
      {
        options.Level = CompressionLevel.Fastest;
      });
      builder.Services.Configure<GzipCompressionProviderOptions>(options =>
      {
        options.Level = CompressionLevel.SmallestSize;
      });
      builder.Services.AddDataProtection();

      builder.Services.AddHttpContextAccessor();
      builder.Services.AddScoped<HttpContextAccessor>();
      builder.Services.AddScoped<IPAddressService>();       // IPADDR

      var app = builder.Build();

      // Configure the HTTP request pipeline.
      if (!app.Environment.IsDevelopment())
      {
        app.UseExceptionHandler("/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
      }

      var webSocketOptions = new WebSocketOptions()
      {
        KeepAliveInterval = TimeSpan.FromSeconds(15)
      };
      app.UseWebSockets(webSocketOptions);
      app.UseResponseCompression();
      app.UseResponseCaching();

      app.UseHttpsRedirection();

      app.UseStaticFiles();
      app.UseAntiforgery();

      app.MapRazorComponents<App>()
          .AddInteractiveServerRenderMode();

      app.Run();
    }
  }
}
