package main

import (
	"log"

	"sale/internal/api/routes"
	"sale/internal/config"
	"sale/internal/utils"

	"github.com/gin-gonic/gin"
)

func main() {
	config.Load()

	utils.InitDB()
	utils.InitLogger()
	utils.AutoMigrate()

	if config.AppConfig.Server.Mode == "release" {
		gin.SetMode(gin.ReleaseMode)
	}

	r := gin.Default()

	routes.SetupRoutes(r)

	addr := ":" + config.AppConfig.Server.Port
	log.Printf("Server starting on %s", addr)
	if err := r.Run(addr); err != nil {
		log.Fatalf("Failed to start server: %v", err)
	}
}
