package outcomes

import (
	"context"
	"fmt"

	"apps/backend/internal/middleware"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

func (l *DeleteConversionLogic) DeleteConversion(req *types.DeleteConversionReq) (*types.OkData, error) {
	uid, ok := middleware.UIDFrom(l.ctx)
	if !ok || uid <= 0 {
		return nil, fmt.Errorf("unauthorized")
	}
	if err := l.svcCtx.Growth.DeleteConversion(l.ctx, uid, req.Id); err != nil {
		return nil, err
	}
	return &types.OkData{Ok: true}, nil
}
