package logic

import (
	"context"
	"net/http"

	"dag-jupyter/internal/api"
	"dag-jupyter/internal/svc"
	"dag-jupyter/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type StopOpLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStopOpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StopOpLogic {
	return &StopOpLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StopOpLogic) StopOp(req *types.DeleteJupyterInfo) (resp *types.Response, err error) {
	err = api.Uninstall(req)
	if err != nil {
		return &types.Response{
			Data: err.Error(),
			Code: http.StatusBadRequest,
		}, nil
	}

	return &types.Response{
		Data: "success",
		Code: http.StatusOK,
	}, nil
}
