package radar

import (
	"context"

	"apps/backend/internal/logic/radarmap"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

func (l *CreateOpportunityReplyLogic) CreateOpportunityReply(req *types.CreateReplyReq) (*types.ReplyVariantPublic, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	r, err := l.svcCtx.Radar.GenerateReply(l.ctx, uid, req.Id, req.Variant)
	if err != nil {
		return nil, err
	}
	return radarmap.Reply(r), nil
}
