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

import dev.adriankuta.flights.domain.search.GetFlightsSearchContentUseCase
import dev.adriankuta.flights.domain.search.entities.SearchOptions
import dev.adriankuta.flights.domain.types.Flight
import dev.adriankuta.flights.model.repository.mappers.toDomain
import dev.adriankuta.model.data.api.FlightService
import javax.inject.Inject

internal class GetFlightsSearchContentUseCaseImpl @Inject constructor(
    private val flightService: FlightService,
) : GetFlightsSearchContentUseCase {

    override suspend fun invoke(searchOptions: SearchOptions): Flight {
        val result = flightService.getFlights(
            origin = searchOptions.origin.code,
            destination = searchOptions.destination.code,
            date = searchOptions.date.toString(),
            adult = searchOptions.adults,
            teen = searchOptions.teens,
            child = searchOptions.children,
        )

        return result.toDomain()
    }
}
