package controllers import ( "fmt" "github.com/gofiber/fiber/v2" "github.com/sujit-baniya/fiber-boilerplate/pkg/services" ) type crearCotizacionRequest struct { ClienteID uint `json:"cliente_id"` Alcance string `json:"alcance"` TipoProyecto string `json:"tipo_proyecto"` Items []services.ItemCotizacion `json:"items"` } // CreateCotizacion genera el PDF de una cotización a partir de la plantilla activa // tipo 'cotizacion' + los items ya calculados por quien llama (Claude decide los // valores consultando /api/v2/tarifas, el backend solo arma y suma el documento). // La lógica real vive en services.CrearCotizacion, compartida con la tool del agente. // POST /api/v2/cotizaciones func CreateCotizacion(c *fiber.Ctx) error { var req crearCotizacionRequest if err := c.BodyParser(&req); err != nil { return c.Status(400).JSON(fiber.Map{"error": err.Error()}) } doc, total, err := services.CrearCotizacion(req.ClienteID, req.Alcance, req.TipoProyecto, req.Items, generadoPorFromContext(c)) if err != nil { return c.Status(400).JSON(fiber.Map{"error": err.Error()}) } return c.Status(201).JSON(fiber.Map{ "ok": true, "message": fmt.Sprintf("Cotización #%d generada", doc.ID), "total": total, "documento": doc, }) } // generadoPorFromContext distingue si la petición vino del dashboard (sesión web, // AuthApi) o de la API admin/agente (AdminApiAuth con ADMIN_API_KEY / bot). func generadoPorFromContext(c *fiber.Ctx) string { if c.Get("X-Agent-Channel") == "telegram" { return "telegram" } if c.Get("Authorization") != "" || c.Get("X-API-Key") != "" { return "claude_api" } return "web" }