package threads_account

import (
	"context"

	pqdomain "haixun-backend/internal/model/publish_queue/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

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

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

func (l *ListPublishQueueItemsLogic) ListPublishQueueItems(req *types.ListPublishQueueHandlerReq) (*types.PublishQueueListData, error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	result, err := l.svcCtx.PublishQueue.List(l.ctx, pqdomain.ListRequest{
		TenantID:  tenantID,
		OwnerUID:  uid,
		AccountID: req.ID,
		Status:    req.Status,
		Page:      req.Page,
		PageSize:  req.PageSize,
	})
	if err != nil {
		return nil, err
	}
	return toPublishQueueListData(result), nil
}
