package plugin

import (
	"net/http"

	"go.uber.org/zap"

	"codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/pkg/httpresponse"
)

// VersionHandler handles version requests from WordPress plugin
type VersionHandler struct {
	logger *zap.Logger
}

// ProvideVersionHandler creates a new VersionHandler
func ProvideVersionHandler(logger *zap.Logger) *VersionHandler {
	return &VersionHandler{
		logger: logger,
	}
}

// VersionResponse represents the response for the version endpoint
type VersionResponse struct {
	Version     string `json:"version"`
	APIVersion  string `json:"api_version"`
	Environment string `json:"environment"`
	Status      string `json:"status"`
}

// Handle processes GET /api/v1/plugin/version requests
func (h *VersionHandler) Handle(w http.ResponseWriter, r *http.Request) {
	h.logger.Debug("Version endpoint called",
		zap.String("method", r.Method),
		zap.String("remote_addr", r.RemoteAddr),
	)

	response := VersionResponse{
		Version:     "1.0.0",
		APIVersion:  "v1",
		Environment: "production", // Could be made configurable via environment variable
		Status:      "operational",
	}

	httpresponse.OK(w, response)
}
