package com.securityc4po.api.pentest

import com.securityc4po.api.BaseEntity
import com.securityc4po.api.configuration.BC_BAD_CAST_TO_ABSTRACT_COLLECTION
import com.securityc4po.api.configuration.MESSAGE_BAD_CAST_TO_ABSTRACT_COLLECTION
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import org.springframework.data.mongodb.core.mapping.Document

@Document(collection = "pentests")
open class PentestEntity(
    data: Pentest
) : BaseEntity<Pentest>(data)

fun PentestEntity.toPentest(): Pentest {
    return Pentest(
        this.data.id,
        this.data.projectId,
        this.data.category,
        this.data.title,
        this.data.refNumber,
        this.data.status,
        this.data.findingIds,
        this.data.commentIds
    )
}

@SuppressFBWarnings(BC_BAD_CAST_TO_ABSTRACT_COLLECTION, MESSAGE_BAD_CAST_TO_ABSTRACT_COLLECTION)
fun List<PentestEntity>.toPentests(): List<Pentest> {
    return this.map {
        it.toPentest()
    }
}
