"""
Factory for creating time-shift parallel executor with dependencies.

Constructs the full dependency tree for parallel execution by provider.
"""

from ..services.time_shift_config_loader import TimeShiftConfigLoader
from ..services.time_shift_config_splitter import TimeShiftConfigSplitter
from ..services.time_shift_job_submitter import TimeShiftJobSubmitter
from ..services.time_shift_job_monitor import TimeShiftJobMonitor
from ..services.time_shift_result_aggregator import TimeShiftResultAggregator
from ..services.time_shift_console_reporter import TimeShiftConsoleReporter
from ..services.time_shift_parallel_executor import TimeShiftParallelExecutor
from ...api.client import APIClient
from ...api.auth import AWSRequestSigner
from ...api.config import ConfigService


def create_parallel_executor() -> TimeShiftParallelExecutor:
    """
    Factory for parallel executor with all dependencies.

    Constructs the full dependency tree:
    - Loads API configuration
    - Creates API client
    - Wires up all specialized services
    - Returns configured parallel executor

    Returns:
        TimeShiftParallelExecutor ready for execution
    """
    # Load API configuration from ~/.czbg/.env
    config_service = ConfigService()
    api_config = config_service.get_api_config()

    # Create AWS request signer for IAM authentication
    signer = AWSRequestSigner()

    # Create API client with IAM authentication
    api_client = APIClient(config=api_config, signer=signer)

    # Create all specialized services
    config_loader = TimeShiftConfigLoader()
    config_splitter = TimeShiftConfigSplitter()
    job_submitter = TimeShiftJobSubmitter(api_client=api_client)
    job_monitor = TimeShiftJobMonitor(api_client=api_client, poll_interval_sec=5)
    result_aggregator = TimeShiftResultAggregator()
    console_reporter = TimeShiftConsoleReporter()

    # Wire up orchestrator with all dependencies
    return TimeShiftParallelExecutor(
        config_loader=config_loader,
        config_splitter=config_splitter,
        job_submitter=job_submitter,
        job_monitor=job_monitor,
        result_aggregator=result_aggregator,
        console_reporter=console_reporter
    )
