package handler

import (
	"net/http"

	"galaxy/model/rest"

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

func InitHandler(c *gin.Context, executor CommandExecutor) {
	var init rest.InitRequest
	if errorResponse(c, c.ShouldBindJSON(&init)) {
		return
	}

	races := make([]string, len(init.Races))
	for i := range init.Races {
		races[i] = init.Races[i].RaceName
	}

	s, err := executor.GenerateGame(races)
	if errorResponse(c, err) {
		return
	}

	c.JSON(http.StatusCreated, s)
}
