package main

import (
	"kontor-api-fiber/pkg/handler"
	"kontor-api-fiber/pkg/schema"
	"log"

	jwtware "github.com/gofiber/contrib/jwt"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/logger"
)

func main() {
	log.Println("Kontor started")

	if err := schema.Connect(); err != nil {
		log.Fatal(err)
	}

	app := fiber.New()

	// app.Use(jwtware.New(jwtware.Config{
	// 	SigningKey: jwtware.SigningKey{Key: []byte("secret")},
	// }))

	//app.Use(logger.New())

	app.Get("/health", handler.GetHealth)
	app.Post("/login", handler.Login)

	api := app.Group("/api", logger.New(), jwtware.New(jwtware.Config{
		SigningKey: jwtware.SigningKey{Key: []byte("secret")},
	}))
	api.Use(logger.New())
	handler.SetupComicRoutes(api)
	handler.SetupMediaRoutes(api)
	// Listen on port 8900
	app.Listen(":8500")

	log.Println("Kontor finished")
}
