package handler

import (
	"github.com/gin-gonic/gin"
	v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
	"github.com/go-nunu/nunu-layout-advanced/internal/service/api/gameShield"
	"github.com/mcuadros/go-defaults"
	"net/http"
)

type GameShieldBackendHandler struct {
	*Handler
	gameShieldBackendService gameShield.GameShieldBackendService
}

func NewGameShieldBackendHandler(
	handler *Handler,
	gameShieldBackendService gameShield.GameShieldBackendService,
) *GameShieldBackendHandler {
	return &GameShieldBackendHandler{
		Handler:                  handler,
		gameShieldBackendService: gameShieldBackendService,
	}
}

func (h *GameShieldBackendHandler) GetGameShieldBackend(ctx *gin.Context) {

}

func (h *GameShieldBackendHandler) AddGameShieldBackend(ctx *gin.Context) {
	req := new(v1.GameShieldBackendArrayRequest)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
		return
	}
	defaults.SetDefaults(req)
	res, err := h.gameShieldBackendService.AddGameShieldBackend(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
		return
	}
	v1.HandleSuccess(ctx, res)
}

func (h *GameShieldBackendHandler) EditGameShieldBackend(ctx *gin.Context) {
	req := new(v1.GameShieldBackendArrayRequest)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
		return
	}
	defaults.SetDefaults(req)
	res, err := h.gameShieldBackendService.EditGameShieldBackend(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
		return
	}
	v1.HandleSuccess(ctx, res)
}

func (h *GameShieldBackendHandler) DeleteGameShieldBackend(ctx *gin.Context) {
	req := new(v1.DelGameShieldBackendRequest)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
		return
	}
	defaults.SetDefaults(req)
	res, err := h.gameShieldBackendService.DeleteGameShieldBackend(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
		return
	}
	v1.HandleSuccess(ctx, res)
}

func (h *GameShieldBackendHandler) ReplacementSourceMachineIp(ctx *gin.Context) {
	req := new(v1.ReplacementSourceMachineIpRequest)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
		return
	}
	defaults.SetDefaults(req)
	err := h.gameShieldBackendService.ReplacementSourceMachineIp(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
		return
	}
	v1.HandleSuccess(ctx, nil)
}