using Back.Data.Contracts;
using Back.Data.Infrastructure.Repository;
using Back.Services;
using Microsoft.EntityFrameworkCore;
using TaxPayer.Infrastructure.Persistence;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<SqlDbContext>(options =>
{
    options.UseSqlServer(builder.Configuration.GetConnectionString("Base"));
});
builder.Services.AddScoped(typeof(IAsyncRepository<>), typeof(RepositoryBase<>));
builder.Services.AddScoped<Back.Services.ServBase>();
string origins = "OriginTaxPayer";
builder.Services.AddCors(options =>
{
    options.AddPolicy(origins,
                          policy =>
                          {
                              policy.WithOrigins("http://localhost:5107")
                                                  .AllowAnyHeader()
                                                  .AllowAnyMethod();
                          });
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseCors(origins);
app.UseAuthorization();

app.MapControllers();

app.Run();
