package routes

import (
	"git.trj.tw/golang/go-gallery/models"
	"git.trj.tw/golang/go-gallery/modules/context"
	"git.trj.tw/golang/go-gallery/routers/account"
	"github.com/gin-gonic/gin"
)

// NewServ - get new service
func NewServ() *gin.Engine {
	r := gin.New()
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	return r
}

// SetDefaultRoutes -
func SetDefaultRoutes(r *gin.Engine) {
	r.GET("/", func(c *gin.Context) {
		accs, err := models.GetAllAccount()
		if err != nil {
			c.JSON(500, gin.H{
				"message": "db error",
			})
			return
		}
		c.JSON(200, accs)
	})

	api := r.Group("/api")
	{
		api.GET("/", func(c *gin.Context) {
			c.JSON(200, gin.H{
				"status":  200,
				"message": "Success",
			})
		})
	}
	accountAPI := api.Group("/account")
	{
		accountAPI.POST("/login", context.PatchContext(account.UserLogin))
	}
}
