BaseReport.kt

package com.sebastmar.module.report.internal

import com.sebastmar.module.report.Report
import com.sebastmar.module.report.internal.domain.SkipReport
import com.sebastmar.module.report.system.SystemWriter

/**
 * Represents a report that can be generated.
 *
 * This class is responsible for orchestrating the generation of a report
 * using a provided [ReportBuilder].
 *
 * @param Output The type of the output generated by the report.
 * @param Builder The type of the [ReportBuilder] used to construct the report content.
 * @property reportBuilder The [ReportBuilder] used to construct the report content.
 * @property systemWriter The [SystemWriter] used to output the generated report.
 * @param skipReport Configuration to determine if this report should be skipped.
 */
internal abstract class BaseReport<Output, Builder : ReportBuilder<Output>>(
    private val skipReport: SkipReport,
    private val reportBuilder: Builder,
    private val systemWriter: SystemWriter<Output>,
) : Report<Output> {
    private val shouldSkipReport: Boolean by lazy { skipReport() }

    override fun write() {
        if (!shouldSkipReport) {
            systemWriter.write(content())
        }
    }

    override fun content(): Output = with(reportBuilder) {
        buildReport()

        return getReport()
    }

    protected abstract fun Builder.buildReport()
}