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"
	"net/http"
)

type GateWayGroupIpHandler struct {
	*Handler
	gateWayGroupIpService service.GateWayGroupIpService
}

func NewGateWayGroupIpHandler(
    handler *Handler,
    gateWayGroupIpService service.GateWayGroupIpService,
) *GateWayGroupIpHandler {
	return &GateWayGroupIpHandler{
		Handler:      handler,
		gateWayGroupIpService: gateWayGroupIpService,
	}
}

func (h *GateWayGroupIpHandler) GetGateWayGroupIp(ctx *gin.Context) {

}

func (h *GateWayGroupIpHandler) GetGateWayGroupIpByGatewayGroupId(ctx *gin.Context)  {
	req := new(v1.GetGateWayGroupIpByGatewayGroupIdRequest)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest,nil)
		return
	}
	res, err := h.gateWayGroupIpService.GetGateWayGroupIpByGatewayGroupId(ctx, req.GatewayGroupId)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, nil)
		return
	}

	v1.HandleSuccess(ctx, res)
}

func (h *GateWayGroupIpHandler) AddGateWayGroupIp(ctx *gin.Context)  {
	req := new(v1.GateWayGroupIpRequest)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
		return
	}

	err := h.gateWayGroupIpService.AddGateWayGroupIp(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
		return
	}
	v1.HandleSuccess(ctx, nil)

}

func (h *GateWayGroupIpHandler) EditGateWayGroupIp(ctx *gin.Context)  {
	req := new(v1.GateWayGroupIpRequest)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
		return
	}

	err := h.gateWayGroupIpService.EditGateWayGroupIp(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
		return
	}
	v1.HandleSuccess(ctx, nil)

}

func (h *GateWayGroupIpHandler) DeleteGateWayGroupIp(ctx *gin.Context)  {
	req := new(v1.DeleteGateWayGroupIpRequest)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
		return
	}

	err := h.gateWayGroupIpService.DeleteGateWayGroupIp(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
		return
	}
	v1.HandleSuccess(ctx, nil)

}

func (h *GateWayGroupIpHandler) GetGateWayGroupIpList(ctx *gin.Context)  {
	req := new(v1.SearchGatewayGroupIpParams)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
		return
	}

	res, err := h.gateWayGroupIpService.GetGateWayGroupIpAdmin(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
		return
	}
	v1.HandleSuccess(ctx, res)

}
