package de.walamana.service

import de.walamana.models.*
import kotlinx.serialization.Serializable


@Serializable
data class Plan (
    val gottesdienste: List<Gottesdienst>,
    val ministranten: List<SimplifiedMinistrant>,
    val marks: List<Mark>
)

object PlanDao {

    suspend fun constructPlan(planId: Int, isAnonymous: Boolean): Plan {
        val gottesdienste = GottesdiensteDao.getGottesdiensteForPlan(planId)
        var ministranten = MinistrantenDao.simplifiedMinistranten()
        if(isAnonymous) {
            ministranten = ministranten.map {
                SimplifiedMinistrant(it.id, it.username, it.firstname, if(it.lastname.isNotEmpty()) it.lastname[0].toString() + "." else "")
            }
        }
        val marks = MarksDao.allMarksForPlan(planId)

        return Plan(gottesdienste, ministranten, marks)
    }

}
