package waf

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

type CdnLogHandler struct {
	*handler.Handler
	cdnLogService waf.CdnLogService
}

func NewCdnLogHandler(
    handler *handler.Handler,
    cdnLogService waf.CdnLogService,
) *CdnLogHandler {
	return &CdnLogHandler{
		Handler:      handler,
		cdnLogService: cdnLogService,
	}
}

func (h *CdnLogHandler) GetCdnLog(ctx *gin.Context) {
	var req v1.GetCdnLog
	if err := ctx.ShouldBind(&req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, err.Error())
		return
	}
	defaults.SetDefaults(&req)
	res, err := h.cdnLogService.GetAccessLog(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, err.Error())
		return
	}
	v1.HandleSuccess(ctx, res)

}
