package api

import (
	"log/slog"
	"net/http"

	"github.com/alexei/docker-watcher/internal/config"
)

// exportConfig handles GET /api/config/export — downloads current state as YAML.
func (s *Server) exportConfig(w http.ResponseWriter, r *http.Request) {
	data, err := config.ExportConfig(s.store)
	if err != nil {
		slog.Error("failed to export config", "error", err)
		respondError(w, http.StatusInternalServerError, "internal server error")
		return
	}

	w.Header().Set("Content-Type", "application/x-yaml")
	w.Header().Set("Content-Disposition", "attachment; filename=docker-watcher.yaml")
	w.WriteHeader(http.StatusOK)
	w.Write(data)
}
