package main

import (
	"context"
	"log"
	"os"
	"os/signal"
	"syscall"

	_ "github.com/jackc/pgx/v5/stdlib"

	"github.com/saveinmed/backend-go/docs"
	"github.com/saveinmed/backend-go/internal/config"
	"github.com/saveinmed/backend-go/internal/server"
)

// @title SaveInMed Performance Core API
// @version 1.0
// @description API REST B2B para marketplace farmacêutico com split de pagamento e rastreabilidade.
// @BasePath /
// @Schemes http
// @contact.name Engenharia SaveInMed
// @contact.email devops@saveinmed.com
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
func main() {
	cfg := config.Load()

	// swagger metadata overrides
	docs.SwaggerInfo.Title = cfg.AppName
	docs.SwaggerInfo.BasePath = "/"

	srv, err := server.New(cfg)
	if err != nil {
		log.Fatalf("boot failure: %v", err)
	}

	ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
	defer stop()

	if err := srv.Start(ctx); err != nil {
		log.Printf("server stopped: %v", err)
		os.Exit(1)
	}
}
