package com.securityc4po.api.pentest

import com.securityc4po.api.configuration.BC_BAD_CAST_TO_ABSTRACT_COLLECTION
import com.securityc4po.api.configuration.MESSAGE_BAD_CAST_TO_ABSTRACT_COLLECTION
import com.securityc4po.api.extensions.getLoggerFor
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import org.springframework.stereotype.Service
import reactor.core.publisher.Mono

@Service
@SuppressFBWarnings(BC_BAD_CAST_TO_ABSTRACT_COLLECTION, MESSAGE_BAD_CAST_TO_ABSTRACT_COLLECTION)
class PentestService(private val pentestRepository: PentestRepository) {

    var logger = getLoggerFor<PentestService>()

    /**
     * Get all [Pentest]s by projectId and category
     *
     * @return list of [Pentest]
     */
    fun getPentests(projectId: String, category: PentestCategory): Mono<List<Pentest>> {
        return pentestRepository.findPentestByProjectIdAndCategory(projectId, category).collectList().map {
            it.map { pentestEntity -> pentestEntity.toPentest() }
        }
    }
}