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

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

func (l *MarkOpportunityReplyUsedLogic) MarkOpportunityReplyUsed(req *types.MarkReplyUsedReq) (*types.MarkReplyUsedData, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	r, advice, err := l.svcCtx.Radar.MarkReplyUsed(l.ctx, uid, req.Id, req.ReplyId, req.Channel, req.AccountId)
	if err != nil {
		return nil, err
	}
	pub := radarmap.Reply(r)
	if pub == nil {
		return nil, err
	}
	return &types.MarkReplyUsedData{Reply: *pub, HealthAdvice: advice}, nil
}
