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 ApproveDraftReviewLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *ApproveDraftReviewLogic) ApproveDraftReview(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.ReviewApproved, req.Reason)
	if err != nil {
		return nil, err
	}
	return growthmap.Review(r), nil
}
