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

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

func (l *SyncMentionInboxLogic) SyncMentionInbox(req *types.SyncMentionInboxHandlerReq) (*types.SyncMentionInboxData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	result, err := l.svcCtx.MentionInbox.SyncFromAPI(l.ctx, mentioninboxdomain.SyncRequest{
		TenantID:  tenantID,
		OwnerUID:  uid,
		AccountID: req.ID,
		Limit:     req.Limit,
		MaxPages:  req.MaxPages,
	})
	if err != nil {
		return nil, err
	}
	return &types.SyncMentionInboxData{
		Synced: result.Synced,
		Ready:  result.Ready,
		Total:  result.Total,
	}, nil
}
