package es.uv.dagarcos.master.bootstrap;

import es.uv.dagarcos.master.domain.*;
import es.uv.dagarcos.master.repository.ShardRepository;
import es.uv.dagarcos.master.repository.ShardLifecycleEventRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MasterDataInitializer {

    @Bean
    CommandLineRunner initShardLifecycleEvents(
            ShardRepository shardRepository,
            ShardLifecycleEventRepository lifecycleRepository) {

        return args -> {
            for (Shard shard : shardRepository.findAll()) {

                ShardLifecycleEvent event = new ShardLifecycleEvent(
                        shard,
                        ShardLifecycleEventType.REGISTER,
                        "Shard precargado y registrado en el sistema"
                );

                lifecycleRepository.save(event);
            }
        };
    }
}