package threads_account

import (
	"context"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

type CancelPublishQueueItemLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCancelPublishQueueItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelPublishQueueItemLogic {
	return &CancelPublishQueueItemLogic{ctx: ctx, svcCtx: svcCtx}
}

func (l *CancelPublishQueueItemLogic) CancelPublishQueueItem(req *types.PublishQueueItemPath) (*types.PublishQueueItemData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	result, err := l.svcCtx.PublishQueue.Cancel(l.ctx, tenantID, uid, req.ID, req.QID)
	if err != nil {
		return nil, err
	}
	return toPublishQueueItemData(result), nil
}
