package ru.ulstu.strategy.api;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import ru.ulstu.user.service.UserService;

import java.util.List;

@Service
public class StrategyEntityCreateExecutor {
    private final List<EntityCreateStrategy> entityCreateStrategies;
    private final UserService userService;

    public StrategyEntityCreateExecutor(List<EntityCreateStrategy> entityCreateStrategies,
                                        UserService userService) {
        this.entityCreateStrategies = entityCreateStrategies;
        this.userService = userService;
    }


    @Scheduled(cron = "0 0 8 * * *")
    public void scheduleExecuteStrategies() {
        entityCreateStrategies.forEach(strategy -> strategy.createEntityIfNeed(userService.findAll()));
    }
}
