package main

import (
	"log"
	"minecraft-profile/handlers"
	"minecraft-profile/middleware"
	"net/http"

	"github.com/gorilla/mux"
)

func main() {
	r := mux.NewRouter()

	r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))

	r.HandleFunc("/robots.txt", handlers.RobotsHandler).Methods("GET")
	r.HandleFunc("/s3cr3t_adm1n_p4th", handlers.SecretPathHandler).Methods("GET")

	r.HandleFunc("/", handlers.IndexHandler).Methods("GET")
	r.HandleFunc("/register", handlers.RegisterHandler).Methods("GET", "POST")
	r.HandleFunc("/login", handlers.LoginHandler).Methods("GET", "POST")
	r.HandleFunc("/logout", handlers.LogoutHandler).Methods("GET")

	r.Handle("/profile", middleware.AuthRequired(http.HandlerFunc(handlers.ProfileHandler))).Methods("GET")
	r.Handle("/user", middleware.AuthRequired(http.HandlerFunc(handlers.UpdateUserHandler))).Methods("PUT")
	r.Handle("/user/skin-history", middleware.AuthRequired(http.HandlerFunc(handlers.AddToSkinHistoryHandler))).Methods("POST")
	r.Handle("/admin", middleware.AdminRequired(http.HandlerFunc(handlers.AdminHandler))).Methods("GET")

	log.Println("Server starting on :8080")
	log.Fatal(http.ListenAndServe(":8080", r))
}
