package antrol

import (
	"net/http"

	antrolService "service/internal/bpjs/antrol/reference"
	"service/pkg/errors"
	"service/pkg/response"

	"github.com/gin-gonic/gin"
)

type AntrolHandler struct {
	service antrolService.Service
}

func NewAntrolHandler(service antrolService.Service) *AntrolHandler {
	return &AntrolHandler{service: service}
}

func (h *AntrolHandler) RegisterRoutes(router *gin.RouterGroup) {
	group := router.Group("/bpjs/antrol/reference")
	{
		group.GET("/poli", h.GetRefPoli)
	}
}

func (h *AntrolHandler) GetRefPoli(c *gin.Context) {
	ctx := c.Request.Context()
	res, err := h.service.GetRefPoli(ctx)
	if err != nil {
		appErr := errors.FromError(err)
		response.Error(c, appErr.HTTPStatus(), appErr.Error(), appErr.Metadata())
		return
	}

	response.Success(c, http.StatusOK, "Successfully retrieved BPJS Antrol Poli reference", res)
}
