package main

import (
	"github.com/go-martini/martini"
	"github.com/xyproto/permissionsql"
)

// martini router
func route(m *martini.ClassicMartini, perm *permissionsql.Permissions) {

	// jwt handler
	// handler := New(Config{
	// 	ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
	// 		return []byte(SignedString), nil
	// 	},
	// 	SigningMethod: jwt.SigningMethodHS256,
	// })

	// find a device by key
	m.Get("/application/v1/device/info", GetDeviceInfoByKey)

	// find a device by identifier
	m.Get("/application/v1/devices/:identifier/info", ApplicationAuthOnDeviceIdentifer, GetDeviceInfoByIdentifier)

	// get devie current status
	m.Get("/application/v1/devices/:identifier/status/current",
		ApplicationAuthOnDeviceIdentifer, CheckDeviceOnline, CheckProductConfig,
		GetDeviceCurrentStatus)

	// get devie latest status
	m.Get("/application/v1/devices/:identifier/status/latest",
		ApplicationAuthOnDeviceIdentifer, CheckDeviceOnline, CheckProductConfig,
		GetDeviceLatestStatus)

	// set device status
	m.Put("/application/v1/devices/:identifier/status",
		ApplicationAuthOnDeviceIdentifer, CheckDeviceOnline, CheckProductConfig,
		SetDeviceStatus)

	// send a command to device
	m.Post("/application/v1/devices/:identifier/commands",
		ApplicationAuthOnDeviceIdentifer, CheckDeviceOnline, CheckProductConfig,
		SendCommandToDevice)

	// and a rule to device
	m.Post("/application/v1/devices/:identifier/rules",
		ApplicationAuthOnDeviceIdentifer, CheckDeviceIdentifier,
		AddRule)
	// // user login
	// m.Post("/api/v1/login", binding.Bind(models.LoginRequest{}),
	// 	UserLogin)
	// // user register
	// m.Post("/api/v1/reg", binding.Bind(models.Reqrequest{}),
	// 	UserRegister)

	// // user api group
	// // jwt check and pass UserToken
	// m.Group("/api/v1/user", func(r martini.Router) {
	// 	// user modify password api
	// 	r.Post("/modifypass", ModifyPassword)
	// 	// user add a product
	// 	r.Post("/product", binding.Bind(models.Product{}), SaveProduct)
	// 	// delete a product
	// 	r.Delete("/product", binding.Bind(models.Product{}), DeleteProduct)
	// 	// get products
	// 	r.Get("/product", GetProducts)
	// }, handler.Serve)

}
