package main

import (
	"log"
	"net/http"

	"github.com/go-macaron/binding"
	"github.com/go-macaron/pongo2"
	"gopkg.in/macaron.v1"
)

func startServer() {
	m := macaron.Classic()
	m.Use(pongo2.Pongoer())
	m.Use(macaron.Static("static"))
	//	m.Get("/", myHandler)

	m.Get("/", statusPage)
	m.Get("/json/status", jsonStatus)
	m.Post("/json/outlet/:outlet/on", jsonOutletPowerON)
	m.Post("/json/outlet/:outlet/off", jsonOutletPowerOFF)
	m.Post("/json/outlet/:outlet/toggle", jsonOutletPowerToggle)

	m.Get("/settings/mqtt", webGETSettingsMQTT)
	m.Post("/json/settings/mqtt", binding.Bind(SettingsMQTTForm{}), webPOSTSettingsMQTT)
	//	m.Post("/settings/mqtt", webPOSTSettingsMQTT)

	m.Get("/boards", func(ctx *macaron.Context) {
		ctx.HTML(200, "boards") // 200 is the response code.
	})

	log.Println("Server is running...")
	log.Println(http.ListenAndServe("0.0.0.0:4000", m))
}
