package workspaces

import (
	"context"
	"fmt"

	"apps/backend/internal/logic/growthmap"
	"apps/backend/internal/middleware"
	growthDomain "apps/backend/internal/module/growth/domain"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

func (l *RejectDraftReviewLogic) RejectDraftReview(req *types.ReviewDecisionReq) (*types.DraftReviewPublic, error) {
	uid, ok := middleware.UIDFrom(l.ctx)
	if !ok || uid <= 0 {
		return nil, fmt.Errorf("unauthorized")
	}
	r, err := l.svcCtx.Growth.DecideReview(l.ctx, uid, req.Id, growthDomain.ReviewRejected, req.Reason)
	if err != nil {
		return nil, err
	}
	return growthmap.Review(r), nil
}
