package server

import (
	"net/http"

	"github.com/fiskerinc/cloud-services/services/jetfire/handlers"

	"github.com/fiskerinc/cloud-services/pkg/httphandlers"
	"github.com/fiskerinc/cloud-services/pkg/logger"

	"github.com/julienschmidt/httprouter"
)

const port string = ":8077"

func StartHTTPServer() {
	router := httprouter.New()
	router.PanicHandler = httphandlers.HttpRouterPanicHandler
	addHandler(router, http.MethodGet, "/reset", handlers.ResetSchemaDefinitions)
	logger.Fatal().AnErr("http.ListenAndServe", http.ListenAndServe(port, router)).Send()
}

func addHandler(router *httprouter.Router, method string, path string, handler http.HandlerFunc) {
	router.HandlerFunc(method, httphandlers.HttpRouterHandleBaseURL(path), handler)
}
