package radar

import (
	"context"

	"apps/backend/internal/logic/radarmap"
	"apps/backend/internal/module/radar/domain"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

func (l *ListSweepsLogic) ListSweeps(req *types.ListSweepsReq) (*types.SweepListData, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	list, total, err := l.svcCtx.Radar.ListSweeps(l.ctx, uid, domain.SweepListFilter{
		WatchID: req.WatchId, Page: req.Page, PageSize: req.PageSize,
	})
	if err != nil {
		return nil, err
	}
	return &types.SweepListData{List: radarmap.SweepList(list), Pagination: radarmap.Pagination(req.Page, req.PageSize, total)}, nil
}
