package information

import (
	"bytes"
	"github.com/gorilla/mux"
	"log"
	"strings"
)

// Following prints all of the registered routes
func AboutRoute(route *mux.Route, _ *mux.Router, _ []*mux.Route) error {
	pathTemplate, err := route.GetPathTemplate()

	var buffer bytes.Buffer

	if err == nil {
		buffer.WriteString("\n\t")
		buffer.WriteString("ROUTE: ")
		buffer.WriteString(pathTemplate)
	}
	pathRegexp, err := route.GetPathRegexp()
	if err == nil {
		buffer.WriteString("\n\t")
		buffer.WriteString("Path regexp: ")
		buffer.WriteString(pathRegexp)
	}
	queriesTemplates, err := route.GetQueriesTemplates()
	if err == nil {
		buffer.WriteString("\n\t")
		buffer.WriteString("Queries templates: ")
		buffer.WriteString(strings.Join(queriesTemplates, ","))
	}
	queriesRegexps, err := route.GetQueriesRegexp()
	if err == nil {
		buffer.WriteString("\n\t")
		buffer.WriteString("Queries regexps: ")
		buffer.WriteString(strings.Join(queriesRegexps, ","))
	}
	methods, err := route.GetMethods()
	if err == nil {
		buffer.WriteString("\n\t")
		buffer.WriteString("Methods: ")
		buffer.WriteString(strings.Join(methods, ","))
	}

	if len := buffer.Len(); len != 0 {

		log.Println(buffer.String())

	}

	return nil
}
