package dev.adriankuta.flights.model.repository.usecases

import dev.adriankuta.flights.domain.stations.GetConnectionsForAirportUseCase
import dev.adriankuta.flights.domain.types.Airport
import dev.adriankuta.flights.model.repository.mappers.toDomain
import dev.adriankuta.model.data.api.RoutesService
import javax.inject.Inject

internal class GetConnectionsForAirportUseCaseImpl @Inject constructor(
    private val routesService: RoutesService,
) : GetConnectionsForAirportUseCase {
    override suspend fun invoke(airport: Airport): Set<Airport> {
        val result = routesService.getRoutes(
            languageCode = "pl",
            departureAirportCode = airport.code,
        )
        return result.map { it.toDomain() }.flatten().toSet()
    }
}
