
// Code generated by generate-dynamic-handler.go; DO NOT EDIT.
// Generated at: 2025-08-28 17:47:19
// Service: VClaim (vclaim)
// Description: BPJS VClaim service for eligibility and SEP management

package handlers

import (
	"context"
	"fmt"
	"net/http"
	"strconv"
	"strings"
	"time"

	"api-service/internal/config"
	"api-service/internal/models/reference"
	"api-service/internal/services/bpjs"
	"api-service/pkg/logger"

	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
	"github.com/google/uuid"
)

// VClaimHandler handles VClaim BPJS services
type VClaimHandler struct {
	service   services.VClaimService
	validator *validator.Validate
	logger    logger.Logger
	config    config.BpjsConfig
}

// VClaimHandlerConfig contains configuration for VClaimHandler
type VClaimHandlerConfig struct {
	BpjsConfig config.BpjsConfig
	Logger     logger.Logger
	Validator  *validator.Validate
}

// NewVClaimHandler creates a new VClaimHandler
func NewVClaimHandler(cfg VClaimHandlerConfig) *VClaimHandler {
	return &VClaimHandler{
		service:   services.NewService(cfg.BpjsConfig),
		validator: cfg.Validator,
		logger:    cfg.Logger,
		config:    cfg.BpjsConfig,
	}
}



// GetPESERTA retrieves Peserta data

// @Summary Get Peserta data
// @Description Get participant eligibility information
// @Tags vclaim,peserta
// @Accept json
// @Produce json

// @Security ApiKeyAuth


// @Param nokartu path string true "nokartu"

// @Success 200 {object} reference.PesertaResponse
// @Failure 400 {object} reference.ErrorResponse
// @Failure 500 {object} reference.ErrorResponse
// @Router /Peserta/:nokartu [get]

func (h *VClaimHandler) GetPESERTA(c *gin.Context) {
	ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second)
	defer cancel()

	// Generate request ID if not present
	requestID := c.GetHeader("X-Request-ID")
	if requestID == "" {
		requestID = uuid.New().String()
		c.Header("X-Request-ID", requestID)
	}

	
	h.logger.Info("Processing GetPeserta request", map[string]interface{}{
		"request_id": requestID,
		"endpoint":   "/Peserta/:nokartu",
		
		"nokartu": c.Param("nokartu"),
		
	})
	

	// Extract path parameters
	
	nokartu := c.Param("nokartu")
	if nokartu == "" {
		
		h.logger.Error("Missing required parameter nokartu", map[string]interface{}{
			"request_id": requestID,
		})
		
		c.JSON(http.StatusBadRequest, reference.ErrorResponse{
			Status:    "error",
			Message:   "Missing required parameter nokartu",
			RequestID: requestID,
		})
		return
	}
	

	// Call service method
	var response reference.PesertaResponse
	
	result, err := h.service.GetPESERTA(ctx, nokartu)
	
	if err != nil {
		
		h.logger.Error("Failed to get Peserta", map[string]interface{}{
			"error":      err.Error(),
			"request_id": requestID,
		})
		
		c.JSON(http.StatusInternalServerError, reference.ErrorResponse{
			Status:    "error",
			Message:   "Internal server error",
			RequestID: requestID,
		})
		return
	}

	// Ensure response has proper fields
	response.Status = "success"
	response.RequestID = requestID
	c.JSON(http.StatusOK, response)
}





// GetSEP retrieves Sep data

// @Summary Get Sep data
// @Description Manage SEP (Surat Eligibilitas Peserta)
// @Tags vclaim,sep
// @Accept json
// @Produce json

// @Security ApiKeyAuth


// @Param nosep path string true "nosep"

// @Success 200 {object} reference.SEPResponse
// @Failure 400 {object} reference.ErrorResponse
// @Failure 500 {object} reference.ErrorResponse
// @Router /SEP/:nosep [get]

func (h *VClaimHandler) GetSEP(c *gin.Context) {
	ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second)
	defer cancel()

	// Generate request ID if not present
	requestID := c.GetHeader("X-Request-ID")
	if requestID == "" {
		requestID = uuid.New().String()
		c.Header("X-Request-ID", requestID)
	}

	
	h.logger.Info("Processing GetSep request", map[string]interface{}{
		"request_id": requestID,
		"endpoint":   "/SEP/:nosep",
		
		"nosep": c.Param("nosep"),
		
	})
	

	// Extract path parameters
	
	nosep := c.Param("nosep")
	if nosep == "" {
		
		h.logger.Error("Missing required parameter nosep", map[string]interface{}{
			"request_id": requestID,
		})
		
		c.JSON(http.StatusBadRequest, reference.ErrorResponse{
			Status:    "error",
			Message:   "Missing required parameter nosep",
			RequestID: requestID,
		})
		return
	}
	

	// Call service method
	var response reference.SEPResponse
	
	result, err := h.service.GetSEP(ctx, nosep)
	
	if err != nil {
		
		h.logger.Error("Failed to get Sep", map[string]interface{}{
			"error":      err.Error(),
			"request_id": requestID,
		})
		
		c.JSON(http.StatusInternalServerError, reference.ErrorResponse{
			Status:    "error",
			Message:   "Internal server error",
			RequestID: requestID,
		})
		return
	}

	// Ensure response has proper fields
	response.Status = "success"
	response.RequestID = requestID
	c.JSON(http.StatusOK, response)
}



// CreateSEP creates new Sep

// @Summary Create Sep
// @Description Manage SEP (Surat Eligibilitas Peserta)
// @Tags vclaim,sep
// @Accept json
// @Produce json

// @Security ApiKeyAuth

// @Param request body reference.SEPRequest true "Sep data"
// @Success 201 {object} reference.SEPResponse
// @Failure 400 {object} reference.ErrorResponse
// @Failure 500 {object} reference.ErrorResponse
// @Router /sep [post]

func (h *VClaimHandler) CreateSEP(c *gin.Context) {
	ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second)
	defer cancel()

	requestID := c.GetHeader("X-Request-ID")
	if requestID == "" {
		requestID = uuid.New().String()
		c.Header("X-Request-ID", requestID)
	}

	
	h.logger.Info("Processing CreateSep request", map[string]interface{}{
		"request_id": requestID,
	})
	

	var req reference.SEPRequest
	if err := c.ShouldBindJSON(&req); err != nil {
		
		h.logger.Error("Invalid request body", map[string]interface{}{
			"error":      err.Error(),
			"request_id": requestID,
		})
		
		c.JSON(http.StatusBadRequest, reference.ErrorResponse{
			Status:    "error",
			Message:   "Invalid request body: " + err.Error(),
			RequestID: requestID,
		})
		return
	}

	// Validate request
	if err := h.validator.Struct(&req); err != nil {
		
		h.logger.Error("Validation failed", map[string]interface{}{
			"error":      err.Error(),
			"request_id": requestID,
		})
		
		c.JSON(http.StatusBadRequest, reference.ErrorResponse{
			Status:    "error",
			Message:   "Validation failed: " + err.Error(),
			RequestID: requestID,
		})
		return
	}

	// Call service method
	var response reference.SEPResponse
	result, err := h.service.CreateSEP(ctx, &req)
	if err != nil {
		
		h.logger.Error("Failed to create Sep", map[string]interface{}{
			"error":      err.Error(),
			"request_id": requestID,
		})
		
		c.JSON(http.StatusInternalServerError, reference.ErrorResponse{
			Status:    "error",
			Message:   "Internal server error",
			RequestID: requestID,
		})
		return
	}

	// Ensure response has proper fields
	response.Status = "success"
	response.RequestID = requestID
	c.JSON(http.StatusCreated, response)
}



// GetRUJUKAN retrieves Rujukan data

// @Summary Get Rujukan data
// @Description Get referral information
// @Tags vclaim,rujukan
// @Accept json
// @Produce json

// @Security ApiKeyAuth


// @Param norujukan path string true "norujukan"

// @Success 200 {object} reference.RujukanResponse
// @Failure 400 {object} reference.ErrorResponse
// @Failure 500 {object} reference.ErrorResponse
// @Router /rujukan/:norujukan [get]

func (h *VClaimHandler) GetRUJUKAN(c *gin.Context) {
	ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second)
	defer cancel()

	// Generate request ID if not present
	requestID := c.GetHeader("X-Request-ID")
	if requestID == "" {
		requestID = uuid.New().String()
		c.Header("X-Request-ID", requestID)
	}

	
	h.logger.Info("Processing GetRujukan request", map[string]interface{}{
		"request_id": requestID,
		"endpoint":   "/rujukan/:norujukan",
		
		"norujukan": c.Param("norujukan"),
		
	})
	

	// Extract path parameters
	
	norujukan := c.Param("norujukan")
	if norujukan == "" {
		
		h.logger.Error("Missing required parameter norujukan", map[string]interface{}{
			"request_id": requestID,
		})
		
		c.JSON(http.StatusBadRequest, reference.ErrorResponse{
			Status:    "error",
			Message:   "Missing required parameter norujukan",
			RequestID: requestID,
		})
		return
	}
	

	// Call service method
	var response reference.RujukanResponse
	
	result, err := h.service.GetRUJUKAN(ctx, norujukan)
	
	if err != nil {
		
		h.logger.Error("Failed to get Rujukan", map[string]interface{}{
			"error":      err.Error(),
			"request_id": requestID,
		})
		
		c.JSON(http.StatusInternalServerError, reference.ErrorResponse{
			Status:    "error",
			Message:   "Internal server error",
			RequestID: requestID,
		})
		return
	}

	// Ensure response has proper fields
	response.Status = "success"
	response.RequestID = requestID
	c.JSON(http.StatusOK, response)
}




