package utils

import (
	"github.com/gin-gonic/gin"
	"github.com/google/uuid"
)

// GetOrSetVisitorID returns an anonymous visitor identifier from cookie, creating one if missing.
func GetOrSetVisitorID(c *gin.Context) string {
	if cookie, err := c.Cookie("visitor_id"); err == nil && cookie != "" {
		return cookie
	}

	id := uuid.New().String()
	c.SetCookie("visitor_id", id, 365*24*3600, "/", "", false, true)
	return id
}
