package gaf3.core.services.code.service.impl

import gaf3.core.services.code.GafCodeConfigure
import gaf3.core.services.code.domain.CodeItem
import gaf3.core.services.code.service.GafCodeStore
import org.springframework.stereotype.Service

@Service("autoCodeStore")
class AutoCodeStore(val config: GafCodeConfigure,
                    val fileStore: FileCodeStore,
                    val dbStore: DBCodeStore,
                    val hybridStore: HybridCodeStore) : GafCodeStore {
    override fun load(type: String): List<CodeItem> {
        val service: GafCodeStore = when (config.getStoreType(type)) {
            GafCodeConfigure.StoreType.db -> dbStore
            GafCodeConfigure.StoreType.file -> fileStore
            else -> hybridStore
        }
        return service.load(type)
    }
}