package containers

import (
	"floares/lib/http/containers"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ListContainers(c *gin.Context) {
	container := containers.List()
	c.JSON(200, gin.H{
		"data": container,
	})
}

func CreateContainer(c *gin.Context) {
	var create containers.Create
	if err := c.BindJSON(&create); err != nil {
		c.JSON(200, gin.H{
			"data":  nil,
			"error": err.Error(),
		})
		return
	}
	id, err := create.Create()
	if err != nil {
		c.JSON(200, gin.H{
			"data":  nil,
			"error": err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"data": id,
		"err":  "",
	})
}
func StartContainer(c *gin.Context) {
	containers.Start(c.Query("id"))
	c.Writer.WriteHeader(http.StatusNoContent)
	return
}
func DeleteContainer(c *gin.Context) {
	containers.Delete(c.Query("id"))
	c.Writer.WriteHeader(http.StatusNoContent)
}
