package radar

import (
	"context"

	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

func (l *TriggerWatchSweepLogic) TriggerWatchSweep(req *types.WatchIdReq) (*types.TriggerSweepData, error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	jobID, err := l.svcCtx.Radar.TriggerSweep(l.ctx, uid, req.Id)
	if err != nil {
		return nil, err
	}
	return &types.TriggerSweepData{JobId: jobID}, nil
}
