using Microsoft.EntityFrameworkCore;
using TestEnvironment;

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.AddCors(options => options.AddPolicy(name: "BookOrigins",
    policy =>
    {
        policy.WithOrigins("http://localhost:4200", "").AllowAnyMethod().AllowAnyHeader();
    }
    ));

var dbHost = "localhost";
var dbName = "librarydb";
var dbPassword = "P@ssw0rd121#";

var connectionString = $"Data Source={dbHost};Initial Catalog={dbName};User ID=sa;Password={dbPassword};Trust Server Certificate=Yes";

builder.Services.AddDbContext<BookDbContext>(opt => opt.UseSqlServer(connectionString));

var app = builder.Build();

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

app.UseCors("BookOrigins");

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
