package api

import (
	"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 {
		respondError(w, http.StatusInternalServerError, "failed to export config: "+err.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)
}
