package dev.fyloz.trial.colorrecipesexplorer.config.properties

import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType
import dev.fyloz.trial.colorrecipesexplorer.model.materialType
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component
import org.springframework.util.Assert

@Component
@ConfigurationProperties(prefix = "entities.material-types")
class MaterialTypeProperties {
    var systemTypes: MutableList<MaterialTypeProperty> = mutableListOf()
    var baseName: String = ""

    data class MaterialTypeProperty(
            var name: String = "",
            var prefix: String = "",
            var usePercentages: Boolean = false
    ) {
        fun toMaterialType(): MaterialType {
            Assert.hasText(name, "A system material type has an empty name")
            return materialType(name = name, prefix = prefix, usePercentages = usePercentages, systemType = true)
        }
    }
}
