// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package threads_account

import (
	"context"

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

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

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

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

func (l *ListPublishAlertsLogic) ListPublishAlerts(req *types.ThreadsAccountPath) (resp *types.PublishAlertsData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	items, err := l.svcCtx.PublishQueue.ListAlerts(l.ctx, tenantID, uid, req.ID)
	if err != nil {
		return nil, err
	}
	list := make([]types.PublishAlertData, 0, len(items))
	for _, item := range items {
		list = append(list, types.PublishAlertData{
			Type: item.Type, Severity: item.Severity, Message: item.Message,
			QueueID: item.QueueID, AccountID: item.AccountID, CreateAt: item.CreateAt,
		})
	}
	return &types.PublishAlertsData{List: list}, nil
}
