package threads_account

import (
	"context"

	mentioninboxdomain "haixun-backend/internal/model/mention_inbox/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

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

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

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

func (l *PublishMentionReplyLogic) PublishMentionReply(req *types.PublishMentionReplyHandlerReq) (*types.PublishMentionReplyData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	result, err := l.svcCtx.MentionInbox.PublishReply(l.ctx, mentioninboxdomain.PublishReplyRequest{
		TenantID:  tenantID,
		OwnerUID:  uid,
		AccountID: req.ID,
		MediaID:   req.MediaID,
		Text:      req.Text,
	})
	if err != nil {
		return nil, err
	}
	return &types.PublishMentionReplyData{
		MediaID:   result.MediaID,
		Permalink: result.Permalink,
	}, nil
}
