package master_data

import (
	"github.com/gin-gonic/gin"
	"github.com/google/uuid"
	"net/http"
	"os"
	"template_blueprint/internal/database"
	"template_blueprint/pkg/database/mongo"
	"template_blueprint/pkg/models/master_data"
)

func InsertDataMaster(c *gin.Context) {
	master := os.Getenv("BLUEPRINT_DB_MASTER")
	var ReqInsertData master_data.ReqInsertData
	errBind := c.Bind(&ReqInsertData)
	if errBind != nil {
		c.JSON(400, gin.H{
			"code": 400,
		})
	}
	db := database.New(master).GetDB()
	mongoDB := mongo.NewDatabaseService(db)
	ReqInsertData.ID = uuid.New().String()
	errInsert := mongoDB.InsertDataMaster(ReqInsertData)
	if errInsert != nil {
		c.JSON(400, gin.H{
			"message": "Failed Insert User",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{"message": "Successfully Inserted User"})
}
