package main

import (
	"net/http"
	"time"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"

	"github.com/swaggo/http-swagger"
	_ "github.com/chunk-hunkman/uml-caddy/docs" // docs is generated by Swag CLI, you have to import it.

)

const (
	purl = "http://plant-uml:8080"
	port = ":8080"
)


// @title           UML-Caddy
// @description     Automatically generate UML diagrams

// @license.name  GNU GENERAL PUBLIC LICENSE Version 3
// @license.url   https://www.gnu.org/licenses/gpl-3.0.en.html
func main() {

	r := chi.NewRouter()

	r.Use(middleware.RequestID)
	r.Use(middleware.RealIP)
	r.Use(middleware.Logger)
	r.Use(middleware.Recoverer)

	r.Use(middleware.Timeout(60 * time.Second))

	r.Get("/swagger/*", httpSwagger.Handler(
		httpSwagger.URL("swagger/doc.json"), //The url pointing to API definition
	))

	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("howdy"))
	})

	r.Route("/puml", func(r chi.Router) {

		r.Get("/k8s", generateK8sPUML)

		//TODO finish importer implementation for infra
		r.Get("/k8sInfra", generateK8sInfraPUML)

	})

	r.Route("/png", func(r chi.Router){

		r.Get("/k8s", generateK8sPNG)

		//TODO finish importer implementation for infra
		r.Get("/k8sInfra", generateK8sInfraPNG)
	})

	http.ListenAndServe(port, r)

}
