// Code generated by genhandler; DO NOT EDIT.

package handlers

import (
    "context"
    "net/http"
    "time"
    "{{.ModuleName}}/internal/models/reference"
    "github.com/gin-gonic/gin"
    "github.com/google/uuid"
)

/* ===== HANDLER STRUCT & CONSTRUCTOR ===== */
type {{.ServiceName}}Handler struct {
    svc reference.{{.ServiceName}}Service
    timeout time.Duration
}

func New{{.ServiceName}}Handler(svc reference.{{.ServiceName}}Service) *{{.ServiceName}}Handler {
    return &{{.ServiceName}}Handler{
        svc: svc,
        timeout: time.Duration({{.Timeout}}) * time.Second,
    }
}

/* ===== ENDPOINTS ===== */
{{range .Endpoints}}
{{/* ---------- GET ---------- */}}
{{if .HasGet}}
{{if $.HasSwagger}}
// @Summary {{.Summary}}
// @Description {{.Description}}
// @Tags {{ join .Tags "," }}
// @Accept json
// @Produce json
{{range .PathParams}}
// @Param {{.}} path string true "{{.}}"
{{end}}
{{if .RequireAuth}}
// @Security ApiKeyAuth
{{end}}
// @Success 200 {object} reference.{{.ResponseModel}}
// @Failure 400 {object} reference.ErrorResponse
// @Failure 500 {object} reference.ErrorResponse
// @Router {{.GetPath}} [get]
{{end}}
func (h *{{$.ServiceName}}Handler) Get{{.NameCamel}}(c *gin.Context) {
    // ... (isi fungsi handler)
}
{{end}}
{{/* ---------- POST ---------- */}}
{{if .HasPost}}
{{if $.HasSwagger}}
// @Summary {{.Summary}}
// @Description {{.Description}}
// @Tags {{ join .Tags "," }}
// @Accept json
// @Produce json
{{if .RequireAuth}}
// @Security ApiKeyAuth
{{end}}
// @Param request body reference.{{.Model}} true "{{.Name}} data"
// @Success 201 {object} reference.{{.ResponseModel}}
// @Failure 400 {object} reference.ErrorResponse
// @Failure 500 {object} reference.ErrorResponse
// @Router {{.PostPath}} [post]
{{end}}
func (h *{{$.ServiceName}}Handler) Create{{.NameCamel}}(c *gin.Context) {
    // ... (isi fungsi handler)
}
{{end}}
{{/* ---------- PUT ---------- */}}
{{if .HasPut}}
{{if $.HasSwagger}}
// @Summary Update {{.Name}}
// @Description {{.Description}}
// @Tags {{ join .Tags "," }}
// @Accept json
// @Produce json
{{range .PathParams}}
// @Param {{.}} path string true "{{.}}"
{{end}}
{{if .RequireAuth}}
// @Security ApiKeyAuth
{{end}}
// @Param request body reference.{{.Model}} true "{{.Name}} data"
// @Success 200 {object} reference.{{.ResponseModel}}
// @Failure 400 {object} reference.ErrorResponse
// @Failure 500 {object} reference.ErrorResponse
// @Router {{.PutPath}} [put]
{{end}}
func (h *{{$.ServiceName}}Handler) Update{{.NameCamel}}(c *gin.Context) {
    // ... (isi fungsi handler)
}
{{end}}
{{/* ---------- PATCH ---------- */}}
{{if .HasPatch}}
{{if $.HasSwagger}}
// @Summary Patch {{.Name}}
// @Description {{.Description}}
// @Tags {{ join .Tags "," }}
// @Accept json
// @Produce json
{{range .PathParams}}
// @Param {{.}} path string true "{{.}}"
{{end}}
{{if .RequireAuth}}
// @Security ApiKeyAuth
{{end}}
// @Param request body reference.{{.Model}} true "Partial {{.Name}} data"
// @Success 200 {object} reference.{{.ResponseModel}}
// @Failure 400 {object} reference.ErrorResponse
// @Failure 500 {object} reference.ErrorResponse
// @Router {{.PatchPath}} [patch]
{{end}}
func (h *{{$.ServiceName}}Handler) Patch{{.NameCamel}}(c *gin.Context) {
    // ... (isi fungsi handler)
}
{{end}}
{{/* ---------- DELETE ---------- */}}
{{if .HasDelete}}
{{if $.HasSwagger}}
// @Summary Delete {{.Name}}
// @Description {{.Description}}
// @Tags {{ join .Tags "," }}
// @Accept json
// @Produce json
{{range .PathParams}}
// @Param {{.}} path string true "{{.}}"
{{end}}
{{if .RequireAuth}}
// @Security ApiKeyAuth
{{end}}
// @Success 204 {object} nil
// @Failure 400 {object} reference.ErrorResponse
// @Failure 500 {object} reference.ErrorResponse
// @Router {{.DeletePath}} [delete]
{{end}}
func (h *{{$.ServiceName}}Handler) Delete{{.NameCamel}}(c *gin.Context) {
    // ... (isi fungsi handler)
}
{{end}}
{{end}}


/* ===== HELPER FUNCTIONS ===== */
func getOrSetRequestID(c *gin.Context) string {
    id := c.GetHeader("X-Request-ID")
    if id == "" {
        id = uuid.New().String()
        c.Header("X-Request-ID", id)
    }
    return id
}

func errorJSON(c *gin.Context, code int, reqID string, err error) {
    c.JSON(code, gin.H{
        "status": "error",
        "message": err.Error(),
        "request_id": reqID,
    })
}
