package com.cameleer.server.app.config;

import com.cameleer.server.core.agent.AgentEventRepository;
import com.cameleer.server.core.agent.AgentEventService;
import com.cameleer.server.core.agent.AgentRegistryService;
import com.cameleer.server.core.agent.RouteStateRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Creates the {@link AgentRegistryService}, {@link AgentEventService},
 * and {@link RouteStateRegistry} beans.
 * <p>
 * Follows the established pattern: core module plain class, app module bean config.
 */
@Configuration
public class AgentRegistryBeanConfig {

    @Bean
    public AgentRegistryService agentRegistryService(AgentRegistryConfig config,
                                                      com.cameleer.server.app.license.LicenseEnforcer enforcer) {
        return new AgentRegistryService(
                config.getStaleThresholdMs(),
                config.getDeadThresholdMs(),
                config.getCommandExpiryMs(),
                current -> enforcer.assertWithinCap("max_agents", current, 1)
        );
    }

    @Bean
    public AgentEventService agentEventService(AgentEventRepository repository) {
        return new AgentEventService(repository);
    }

    @Bean
    public RouteStateRegistry routeStateRegistry() {
        return new RouteStateRegistry();
    }
}
