package api

import (
	"fr.latosa-escrima/api/users"
	"fr.latosa-escrima/core"
)

var UserRoutes = map[string]core.Handler{
	"/users/login": {
		Handler:     users.HandleLogin,
		Middlewares: []core.Middleware{Methods("POST"), CSRFMiddleware}},
	// Could add users:own:get permission there, but don't think it's
	// necessary
	"/users/me": {
		Handler:     users.HandleMe,
		Middlewares: []core.Middleware{Methods("GET"), AuthJWT}},
	"/users": {
		Handler: users.HandleUsers,
		Middlewares: []core.Middleware{Methods("GET"),
			HasPermissions("users", "get"), AuthJWT}},
	"/users/new": {
		Handler: users.HandleNew,
		Middlewares: []core.Middleware{Methods("POST"),
			HasPermissions("users", "insert"), AuthJWT}},
	"/users/{user_uuid}": {
		Handler: users.HandleUser,
		Middlewares: []core.Middleware{Methods("GET"),
			HasPermissions("users", "get"), AuthJWT}},
	"/users/{user_uuid}/delete": {
		Handler: users.HandleDelete,
		Middlewares: []core.Middleware{Methods("DELETE"),
			HasPermissions("users", "delete"), AuthJWT}},
	"/users/{user_uuid}/update": {
		Handler: users.HandleUpdate,
		Middlewares: []core.Middleware{Methods("PATCH"),
			HasPermissions("users", "update"), AuthJWT}},
	"/users/{user_uuid}/roles": {
		Handler: users.HandleRoles,
		Middlewares: []core.Middleware{Methods("GET"),
			HasPermissions("users", "get"), AuthJWT}},
	"/users/{user_uuid}/roles/{role_id}/add": {
		Handler: users.HandleAddRole,
		Middlewares: []core.Middleware{Methods("PATCH"),
			HasPermissions("users", "update"), AuthJWT}},
	"/users/{user_uuid}/roles/{role_id}/remove": {
		Handler: users.HandleRemoveRole,
		Middlewares: []core.Middleware{Methods("PATCH"),
			HasPermissions("users", "update"), AuthJWT}},
}
