package cloud

import (
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/cloud"
	"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
	"io"
	"k8s.io/apimachinery/pkg/util/json"
	"net/http"

	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
	container "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/cloud"
)

func ContainerDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req container.DeleteParam
		body, err := io.ReadAll(r.Body)
		if err != nil {
			result.ParamErrorResult(r, w, err)
			return
		}

		if err = json.Unmarshal(body, &req); err != nil {
			result.ParamErrorResult(r, w, err)
			return
		}

		l := cloud.NewContainerDeleteLogic(r.Context(), svcCtx)
		resp, err := l.ContainerDelete(&req)
		result.HttpResult(r, w, resp, err)
	}
}
