package routes

import (
	"gitlab.com/pactual1/backend/controllers"
	"gitlab.com/pactual1/backend/middlewares"

	"github.com/gin-gonic/gin"
)

func RegisterPublicRoutes(r *gin.Engine) {

	// Health checks
	r.GET("/health", controllers.HealthCheck)

	// Map dashboard
	r.GET("/dashboard/map/contract/devices", middlewares.AuthMiddleware(), controllers.GetDevicesByContract)
	r.GET("/dashboard/map/contracts", middlewares.AuthMiddleware(), controllers.GetLatestContracts)
	r.GET("/dashboard/map/device_data", middlewares.AuthMiddleware(), controllers.GetDeviceData)

	// Invoices
	r.GET("/invoices", middlewares.AuthMiddleware(), controllers.GetInvoices)
	r.GET("/invoices/:id", middlewares.AuthMiddleware(), controllers.GetInvoiceByID)

	r.POST("/device_data/save", controllers.SaveDeviceInfo)
	r.GET("/buyers", middlewares.AuthMiddleware(), controllers.ListCompanies)
	r.GET("/products", middlewares.AuthMiddleware(), middlewares.AuthMiddleware(), controllers.ListProductTemplates)
	r.GET("/templates", middlewares.AuthMiddleware(), controllers.ListTextTemplates)
	r.POST("/templates/save", middlewares.AuthMiddleware(), controllers.CreateTextTemplate)
	r.GET("/products/:template_id", middlewares.AuthMiddleware(), controllers.GetProductTemplate)

	// Contracts
	r.GET("/contracts/statuses", middlewares.AuthMiddleware(), controllers.GetContractStatuses)
	r.GET("/contracts", middlewares.AuthMiddleware(), controllers.GetBuyerContracts)
	r.POST("/contracts/create", middlewares.AuthMiddleware(), controllers.CreateContract)

	r.GET("/contracts/:contract_id", middlewares.AuthMiddleware(), controllers.GetContractByID)
	r.PATCH("/contracts/:contract_id", middlewares.AuthMiddleware(), controllers.UpdateContract)

	// Locations
	r.GET("/locations", middlewares.AuthMiddleware(), controllers.SearchPlace)

	// Notifications
	r.GET("/notifications", middlewares.AuthMiddleware(), controllers.GetNotifications)

	// Stats
	r.GET("/stats/measurements", middlewares.AuthMiddleware(), controllers.GetCompanyRelatedDeviceInfoCount)
	r.GET("/stats/devices", middlewares.AuthMiddleware(), controllers.GetCompanyRelatedDeviceInfoCountWithTempRange)
	r.GET("/stats/contracts", middlewares.AuthMiddleware(), controllers.GetContractCountByStatus)
	r.GET("/stats/contracts/total", middlewares.AuthMiddleware(), controllers.GetTotalContractCount)
	r.GET("/stats/invoices", middlewares.AuthMiddleware(), controllers.GetInvoiceCountByStatus)
	r.GET("/stats/milestones", middlewares.AuthMiddleware(), controllers.GetContractsMatchingDeviceLocation)

	//Users
	r.POST("/user/reset/password", controllers.ResetPassword)
	r.POST("/user/set/password", controllers.UpdatePassword)
	r.POST("/user/login", controllers.Login)
	r.POST("/user/logout", controllers.Logout)
}
