package main

import (
	"awesome-back/internal/datastore"
	"awesome-back/internal/handler"
	"awesome-back/internal/service"

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

func main() {
	// Инициализация репозиториев
	coffeeRepo := datastore.NewMockCoffeeRepository()
	pastryRepo := datastore.NewMockPastryRepository()
	orderRepo := datastore.NewMockOrderRepository()

	// Инициализация сервисов
	coffeeService := service.NewCoffeeService(coffeeRepo)
	pastryService := service.NewPastryService(pastryRepo)
	orderService := service.NewOrderService(orderRepo)

	// Инициализация обработчиков
	coffeeHandler := handler.NewCoffeeHandler(coffeeService)
	pastryHandler := handler.NewPastryHandler(pastryService)
	orderHandler := handler.NewOrderHandler(orderService)

	// Настройка маршрутов
	router := gin.Default()
	setupRoutes(router, coffeeHandler, pastryHandler, orderHandler)

	router.Run(":8080")
}

func setupRoutes(router *gin.Engine, coffeeHandler *handler.CoffeeHandler, pastryHandler *handler.PastryHandler, orderHandler *handler.OrderHandler) {
	api := router.Group("/api/v1")
	{
		// Кофе
		coffeeRoutes := api.Group("/coffees")
		{
			coffeeRoutes.GET("/", coffeeHandler.GetCoffees)
			coffeeRoutes.GET("/:id", coffeeHandler.GetCoffeeByID)
		}

		// Выпечка
		pastryRoutes := api.Group("/pastries")
		{
			pastryRoutes.GET("/", pastryHandler.GetPastries)
			pastryRoutes.GET("/:id", pastryHandler.GetPastryByID)
			pastryRoutes.GET("/category/:category", pastryHandler.GetPastriesByCategory)
		}

		// Заказы
		orderRoutes := api.Group("/orders")
		{
			orderRoutes.GET("/", orderHandler.GetOrders)
			orderRoutes.GET("/:id", orderHandler.GetOrderByID)
			orderRoutes.POST("/", orderHandler.CreateOrder)
		}
	}
}
